Hey, I haven't found any useful resources on this. Maybe I'm using the wrong keywords, so I figured I should ask here:
Why do annotations not allow interfaces as attribute types?
public interface MyInterface {
String upper();
}
public @interface MyAnnotation {
MyInterface value(); // Invalid type 'MyInterface' for annotation member
}
For some more context: I actually want to pass an enum, but use an interface to define a standard method (implementation can vary).
This is just an example:
public enum MyEnum implements MyInterface {
1("One"),
2("Two");
private String string;
public MyEnum(String string) {
this.string = string;
}
@Override
public String upper() {
return string.toUpperCase();
}
}
@MyAnnotation(MyEnum.1)
public class MyClass {
// ... could then get the value and use `MyInterface#upper`
}