Hello,

A follow-up on defining a final field RELEASE_CURRENT as an alias for the latest SourceVersion constant to allow easier updating of annotations using SourceVersion constants. Somewht surprisingly, this is not legal Java code; an annotation must use an enum constant directly and not a constant expression which evaluates to an enum constant.

This rules is given in JLS 9.7.1 Normal Annotations:

T [ the element type] is not an array type, and the type of V [the element value] is assignment compatible (§5.2) with T, and:

If T is a primitive type or String, then V is a constant expression (§15.28). If T is Class or an invocation of Class (§4.5), then V is a class literal (§15.8.2).
    If T is an enum type (§8.9), then V is an enum constant (§8.9.1).
    V is not null.
https://docs.oracle.com/javase/specs/jls/se9/html/jls-9.html#jls-9.7.1

The wording goes back to JLS 3rd edition which introduced enums and annotations.

Formally, the constant expression concept in JLS 15.28 only applies to primitive types and Strings. Presumably, it would not be too difficult to expand this concept to include class literals and enum constants.

In any case, in the mean time the suggested idiom will not work and the changes of RELEASE_9 => RELEASE_10 will need to stay.

Updated webrev with a minor merge:

    http://cr.openjdk.java.net/~darcy/8173382.3/

Cheers,

-Joe

Reply via email to