Final strings in annotations applying to class members
John Spicer
jhs at edg.com
Tue Jan 28 08:14:13 PST 2014
Javac 8 accepts:
@interface Annot {
String str();
}
class Test {
final String CONST_STR="something";
@Annot( str = CONST_STR )
class Foo {}
@Annot( str = CONST_STR )
void f(){}
}
It rejects only the second annotation use in the example below (complaining that CONST_STR cannot be referenced from a static context).
Given that CONST_STR is a constant expression, I could see allowing both uses. Is there a rationale for allowing only the use on the class?
Thanks,
John.
@interface Annot {
String str();
}
class Test {
final String CONST_STR="something";
@Annot( str = CONST_STR )
static class Foo {}
@Annot( str = CONST_STR )
static void f(){}
}
More information about the compiler-dev
mailing list