Re: Default for annotation members with type class

"Milles, Eric (TR Technology) via users" <users-GSC0n/0aZo1d/SJB6HiN2Ni2O/[email protected]> Tue, 15 Apr 2025 13:01:10 +0000
Newsgroups gmane.comp.lang.groovy.user
Message-ID <PH7PR03MB722464FFB7466214C7EB4B668AB22@PH7PR03MB7224.namprd03.prod.outlook.com>
You should be able to use "default []".  I don't think it supports "default new Class[0]".  Is this under Static Type Checking or Static Compilation?

NOTE: https://issues.apache.org/jira/browse/GROOVY-11492 item 3 covers the missing "default {}" support.


________________________________
From: Saravanan Palanichamy <[email protected]>
Sent: Tuesday, April 15, 2025 4:21 AM
To: users-GSC0n/0aZo1d/SJB6HiN2Ni2O/[email protected] <users-GSC0n/0aZo1d/SJB6HiN2Ni2O/[email protected]>; dev-GSC0n/0aZo1d/[email protected] <dev-GSC0n/0aZo1d/SJB6HiN2Ni2O/[email protected]>
Subject: [EXT] Default for annotation members with type class

External Email: Use caution with links and attachments.

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