Queries about JDK-8035890
Alex Buckley
alex.buckley at oracle.com
Thu Mar 13 18:12:32 UTC 2014
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