Philip Graf
09/13/2022, 7:37 AMdata class Pet(val names: @get:NonNull List<@get:NonNull String>)
to compile to
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:
@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
data class Pet(@get:NonNull val names: List<String>)
then it compiles to
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)?