Final strings in annotations applying to class members
Joel Borggrén-Franck
joel.franck at oracle.com
Wed Jan 29 09:57:55 PST 2014
True,
But doesn’t that mean there is stil a bug here, just not the one we think?
cheers
/Joel
On 29 Jan 2014, at 18:07, Jonathan Gibbons <jonathan.gibbons at oracle.com> wrote:
> Just checking ...
>
> CONSTR_STR is declared "final String", not "static final String" ...
>
> -- Jon
>
>
> On 01/29/2014 05:34 AM, Joel Borggren-Franck wrote:
>> John, Alex,
>>
>> Thanks for the bug report. I filed:
>>
>> https://bugs.openjdk.java.net/browse/JDK-8033132
>>
>> cheers
>> /Joel
>>
>> On 2014-01-28, Alex Buckley wrote:
>>> Looks like a javac bug. The element value CONST_STR is indeed a
>>> constant expression (gives the simple name of a constant variable),
>>> and the type of CONST_STR is a String, so JLS 9.7.1 says all your
>>> annotations are legal.
>>>
>>> Alex
>>>
>>> On 1/28/2014 8:14 AM, John Spicer wrote:
>>>> 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