Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to code optional default annotation value for Annotation TYPE

According to error-setting-a-default-null-value-for-an-annotations-field

its not possible to affect null to an optional default value, here my case

having

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE) 
public @interface SubView {
    Class EntityType();
    String[] Listing();
}

how to encode the default value for the optional SubView property?

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface SubTab {
    String name();
    String[] Fields() default {};
    SubView SubView() default ??? ; //this is optional how to code it?
}
like image 653
Nassim MOUALEK Avatar asked May 03 '26 15:05

Nassim MOUALEK


1 Answers

trial and error

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface SubTab {
    String name();
    String[] Fields() default {};
    SubView SubView() default @SubView(Listing={}, EntityType=Object.class);
}
like image 55
Nassim MOUALEK Avatar answered May 05 '26 05:05

Nassim MOUALEK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!