How to create a Java annotation containing an array of unknown enums? -
the annotation trying create looks this
@retention(value = retentionpolicy.runtime) @target(value = { elementtype.field }) public @interface enumparameter { enum<?>[] disallowedvalues() default {}; } however, next error "invalid type enum[] annotation attribute enumparameter.disallowedvalues; primitive type, string, class, annotation, enumeration permitted or 1-dimensional arrays thereof" it. intend utilize indicate values within enum not valid field. don't know type because intend utilize supplement ui creation , type of enum encountered.
edit clarification.
say have enum,
enum direction{ left, right, both; } and have field,
direction turnsignal; i indicate turn signal cannot have both.
@enumparameter(disallowedvalues = {direction.both}) direction turnsignal; i've been made aware of fact seems impossibility of now. there reason disallowed? considered bad style utilize enum's in fashion?
would work:
@target(value = elementtype.field) @retention(value = retentionpolicy.runtime) public @interface myannotation { class<? extends enum<?>> enumclass(); string[] disallowedvalues(); } used like
@myannotation(enumclass = direction.class, disallowedvalues = {"left", "right"}) direction turnsignal; java enums annotations
No comments:
Post a Comment