Friday, July 29, 2011

Compile-time constants in Java annotation element values

In hindsight, this should've been obvious:
public class CompileTimeConstantsTest {
 
    @interface Awesome { String value(); }
 
    private static final String X = "X";
    private final int a = 1;
    public final int b = 1;

    @Awesome(a < b ? X : X + X) // compiles just fine
    int whatever;
 
}

No comments:

Post a Comment