Reflection Kotlin:获取方法参数值
我正在尝试将参数值传递给我正在穿越的方法。 我现在得到它的方法是使用连接点参数 代码:Reflection Kotlin:获取方法参数值,reflection,kotlin,aop,Reflection,Kotlin,Aop,我正在尝试将参数值传递给我正在穿越的方法。 我现在得到它的方法是使用连接点参数 代码: @Around("@annotation(Log)") fun log(joinPoint: ProceedingJoinPoint): Any { val signature = joinPoint.signature as MethodSignature val methodName = signature.method.name val parameterTypes = sig
@Around("@annotation(Log)")
fun log(joinPoint: ProceedingJoinPoint): Any {
val signature = joinPoint.signature as MethodSignature
val methodName = signature.method.name
val parameterTypes = signature.method.parameterTypes
var paramValues = ""
// TODO: make this a bit more useful
logger.info("begin execution of $methodName")
val startTime = System.currentTimeMillis()
val result = joinPoint.proceed()
joinPoint.args.iterator().forEach {x -> paramValues += x.toString()}
logger.info("complete execution of $methodName($paramValues) took " +
(System.currentTimeMillis() - startTime)/1000.0 + "s")
return result
}
我想知道是否有一种方法可以使用方法反射来获取它(参数值)
我尝试通过这种方式获取值,但没有成功,最终使用joinPoint获取 反射基本上是从.class文件读取数据的一种方法。它不能用于访问仅在运行时存在的信息,例如单个方法调用的参数。反射基本上是从.class文件读取数据的一种方法。它不能用于访问仅在运行时存在的信息,例如单个方法调用的参数。。。对谢谢:)现在我觉得问这个很愚蠢:(…你能写下这个作为答案吗?为了未来的智慧寻求者?