Re: Default for annotation members with type class

Paul King <[email protected]> Tue, 15 Apr 2025 20:44:23 +1000
Newsgroups gmane.comp.lang.groovy.user
Message-ID <CAMbkE7RBNXYDwXUWjHPTbfTdh5m2LNqk1wp=-zeWME-UESKs3Q@mail.gmail.com>
If you define it without static type checking, it is fine to use the
square brackets. It is possibly a bug to give those errors when type
checking is in play.

FYI, there have been previous discussions about supporting the curly
brace syntax too.

Eric has an issue here:
https://issues.apache.org/jira/browse/GROOVY-11492

Daniel did a partial PR here:
https://github.com/apache/groovy/pull/691

Cheers, Paul.


On Tue, Apr 15, 2025 at 7:22 PM Saravanan Palanichamy
<[email protected]> wrote:
>
> Hello Groovy users
>
> What is the right way to define this java annotation in groovy? I am testing this out in Groovy 5.0, I have not tried 4.x.
>
> I tried using [] after the default keyword, but I get the error
>
> "Cannot return value of type java.util.ArrayList<#E> for method returning java.lang.Class<?>[]" and
> "Cannot return value of type java.util.ArrayList<#E> for method returning java.lang.Class<? extends MyClazz>[]"
>
> @Target({ ElementType.METHOD })
> @Retention(RetentionPolicy.RUNTIME)
> public @interface MyAnnotation {
>
>     Class<?>[] groups() default {};
>
>     Class<? extends MyClazz>[] payloads() default {};
>
> }
>
>
> regards
> Saravanan