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
<chava...@gmail.com> 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

Reply via email to