Mike R
08/05/2019, 3:05 AMannotation class Queueable
with a Target of AnnotationTarget.FUNCTION
.
I'm not finding any documentation anywhere on how I can accomplish the rest of what I'd like to do though...
In Python, for example, I can annotate a function and access it's arguments and other properties about it since the annotation wraps the function. Am I thinking about annotations incorrectly in Kotlin?Amirul Zin
08/05/2019, 3:48 AM@Retention(RetentionPolicy.RUNTIME)
2. You can then access this via reflection.
I attached a simple snippet below in Java. How you do it in Kotlin and finally achieve what you want will be left as an exercise 😄karelpeeters
08/05/2019, 6:28 AMclass Test {
val queue = ArrayDeque<() -> Unit>()
private fun wrap(block: () -> Unit) {
queue.add(block)
}
fun foo(arg: String) = wrap {
println("foo $arg")
}
}
Because you seem to be used to Python I'll note that the =
in foo
is just an expression body, you don't actually assign foo
to something.