Actually, the question in the title. When trying to compile something like this:

@Retention(AnnotationRetention.RUNTIME) @Target(AnnotationTarget.FUNCTION) annotation class Argument(val name: String, val completion: () -> Collection<String>) 

I get an error that says () -> Collection<String> - Invalid type of annotation member. I understand that to do what I want is impossible?

  • one
    Most likely, yes, the annotations should have constants (in java, but generally the context of using annotations, regardless of language, is obligatory, therefore the requirement to use only constants and expressions that the compiler can calculate "seems reasonable. - etki
  • Because annotation parameters can only be of such types: primitives, String, Class, Enum, another annotation, an array of the above. Obviously lambda is an object of some other type. - Sergey
  • Indeed, in Java, it is also impossible to use any objects (except for strings) as an annotation parameter. - Radviger Squareland

0