Kotlin:获取方法参数值

Kotlin: Get method parameter values

我正在尝试获取传递给我正在穿越的方法的参数值。 我现在得到它的方式是使用连接点参数。

代码:

@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 文件中读取数据的方法。它不能用于访问仅在运行时存在的信息,例如各个方法调用的参数。