Reputation: 763
I have an interface which multiple enums are implementing, i.e
public interface MinorCodes {
public abstract int code();
public abstract String description();
}
public enum IdentityMinorCodes implements MinorCodes {
IDENTITY_UPLOAD_PICTURE_CODE(1, "Error while trying to upload a picture."),
}
Now I want to have a custom annotation which has a value type of one of these concrete enum values, i.e
public @interface PokenService {
MinorCodes[] exceptions();
}
But of course I cannot return an interface here.
Does anyone know any solution or workaround to this?
Thanks in advance.
Upvotes: 1
Views: 843
Reputation: 36115
You could create an additional enum that wraps all your MinorCodes enum values:
public enum MinorCodesWrapper {
IDENTITY_UPLOAD_PICTURE_CODE(IdentityMinorCodes.IDENTITY_UPLOAD_PICTURE_CODE),
SOME_CODE(AnotherMinorCodes.SOME_CODE);
private final MinorCodes _wrapped;
MinorCodesWrapper(MinorCodes wrapped) {
_wrapped = wrapped;
}
public MinorCodes getWrapped() {
return _wrapped;
}
}
public @interface PokenService {
MinorCodesWrapper[] exceptions();
}
Not pretty, but works ;)
Upvotes: 2