Queries about JDK-8035890
Jan Lahoda
jan.lahoda at oracle.com
Thu Mar 27 23:09:35 UTC 2014
Alex,
I have a few more questions on this. Considering these declarations of
annotation types:
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
@interface DA { }
@Target(ElementType.TYPE_USE)
@interface TA { }
Do I understand correctly that these are supposed to be valid:
public <T> @DA int foo1() { return 0;}
public <T> @DA void foo2() { }
public <T> @TA int foo3() { return 0;}
These are supposed to be invalid:
public class Foo {
<T> @DA Foo() { }
<T> @TA Foo(int i) { }
}
I am unsure about:
public <T> @TA void foo4() { return 0;}
Thanks,
Jan
On 03/14/2014 12:45 PM, Jan Lahoda wrote:
> Thanks a lot for explanations, Alex! I've filled a separate bug for the
> problem with RuntimeInvisibleAnnotations in anonymous innerclass:
> JDK-8037348.
>
> Jan
>
> On 03/13/2014 07:12 PM, Alex Buckley wrote:
>> On 3/13/2014 5:38 AM, Jan Lahoda wrote:
>>> I have two questions on JDK-8035890 - any insights on them are very
>>> welcome.
>>>
>>> 1. Consider this source code:
>>> ---
>>> public class AnnotAfterTypeParams {
>>> public <T> @Decl int foo() { return 0; }
>>> }
>>> @interface Decl { }
>>> ---
>>>
>>> javac currently accepts this code - is that correct? (I could not find a
>>> point in the specification to support this.)
>>
>> javac is correct.
>>
>> Early drafts of JLS8 did not allow annotations after the type parameter
>> section of a method declaration, but javac and ecj did. This was
>> discussed in the thread "type annotations on generic method return type"
>> [1] and fortunately JLS8 (section 8.4) was corrected in time for the
>> Final Release of JSR 337. [If you're not using JLS8 from that Final
>> Release, now is the time to delete your PDF and get it.]
>>
>> [1]
>> http://mail.openjdk.java.net/pipermail/type-annotations-spec-comments/2014-February/thread.html
>>
>>
>>
>>> 2. Consider this source code:
>>> ---
>>> import java.lang.annotation.*;
>>> public class AnnotCopiedToAnonymous {
>>> private Object o = new @Annot Object() { };
>>> }
>>> @Target({ElementType.TYPE, ElementType.TYPE_USE})
>>> @interface Annot { }
>>> ---
>>>
>>> The generated anonymous innerclass (AnnotCopiedToAnonymous$1) has the
>>> Annot annotation as a declaration annotation in its
>>> RuntimeInvisibleAnnotations in addition to having it in its
>>> RuntimeInvisibleTypeAnnotations with a supertype target. Is it intended
>>> to have the annotation as a declaration annotation?
>>
>> It is not intended.
>>
>> The existence of the Runtime[In]VisibleAnnotations attribute in the
>> anonymous class file was discussed in the thread "Desugaring of
>> anonymous classes" [2]. This led to a bug report on type-annotations-dev
>> [3]. That said, the second case in the reported bug JDK-8023682 has only
>> @Target(ElementType.TYPE) - no TYPE_USE as in your example. Still, the
>> intent from [2] was to _not_ generate Runtime[In]VisibleAnnotations - I
>> believe ecj does not generate it.
>>
>> (A long time ago [4], I said it was OK to generate it, but that was
>> before applicability was clarified.)
>>
>> [2]
>> http://mail.openjdk.java.net/pipermail/type-annotations-spec-experts/2013-August/thread.html
>>
>>
>>
>> [3]
>> http://mail.openjdk.java.net/pipermail/type-annotations-dev/2013-August/001209.html
>>
>>
>>
>> [4]
>> http://mail.openjdk.java.net/pipermail/type-annotations-spec-experts/2013-February/000063.html
>>
>>
>>
>> Alex
More information about the type-annotations-dev
mailing list