我定义了自己的自定义注解
@Target(value={ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface MyCustomAnnotation {
Class<?> myType();
}
如果有的话,我怎样才能使属性成为可选的
最佳答案
您可以provide a default value对于属性:
@Target(value={ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface MyCustomAnnotation {
Class<?> myType() default Object.class;
}
关于java自定义注解: make an attribute optional,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1357945/