Hi all, I'm trying to get the compiler to compile ...
# compiler
p
Hi all, I'm trying to get the compiler to compile a data class so that I have annotations on the getter's return type and return type parameter in the generated bytecode, e.g. something like
Copy code
data class Pet(val names: @get:NonNull List<@get:NonNull String>)
to compile to
Copy code
public getNames()Ljava/util/List;
  @Lorg/eclipse/microprofile/graphql/NonNull;() : METHOD_RETURN, null
  @Lorg/eclipse/microprofile/graphql/NonNull;() : METHOD_RETURN, 0;
However, if I compile the data class above, I get two compile errors for each annotation: - This annotation is not applicable to target 'undefined target' and use site target '@get' - This annotation is not applicable to target 'type usage' and use site target '@get' The NonNull annotation is from the Java library microprofile-graphql-api:
Copy code
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
@Documented
public @interface NonNull {
}
If I put the annotion on the constructor argument
Copy code
data class Pet(@get:NonNull val names: List<String>)
then it compiles to
Copy code
public final getNames()Ljava/util/List;
  @Lorg/eclipse/microprofile/graphql/NonNull;()
as I would expect. Is it not possible to use use-site targets on types and type parameters? Is this a limitation/future feature/bug of the compiler? Or is the annotation missing a target (it has the target TYPE_USE)?