在运行时对参数进行Android Java / Kotlin注释评估

时间:2018-10-04 12:57:35

标签: java android kotlin annotations android-annotations

我有一个这样的注释:

@Target(AnnotationTarget.VALUE_PARAMETER, 
AnnotationTarget.LOCAL_VARIABLE, AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.RUNTIME)
annotation class TestAnnotation

现在在函数调用中,我想查看参数是否带有注释:

fun testMe(myValue: Any) {
    // Want to see if "myValue" is annotated with "TestAnnotation" or not in runtime
    println(myValue::class.java.annotations.size)
}

testMe的呼叫在下面

 testMe(@TestAnnotation "dummy value")

我没有得到计数0。获取与参数关联的注释的任何其他方法。我在Java和Kotlin中都尝试过,并且两个地方都使用相同的0。我现在可以使用任何一种语言(java / kotlin)提供解决方案。

0 个答案:

没有答案
相关问题