https://kotlinlang.org logo
Title
u

user

07/12/2022, 7:51 AM
How to set annotations on a method using reflection? I'm trying to unit test an aspect. val joinPoint = mock() val methodSignature = mock() val roleArray = arrayOf("someTestRole") val annotation = AccessCheck::class.constructors.first().call(roleArray) val method = this.javaClass.getMethod("myMethod") method.setAccessible(true) a) method.annotations = roleArray b) method.annotations[0] = annotation Cannot invoke b) because method.annotations returns null. Cannot invoke a) because method.annotations is val. Cannot...