receiver annotations

Alex Buckley alex.buckley at oracle.com
Wed Nov 28 17:22:55 PST 2012


Annotations on type arguments of the receiver type are legal.

For use cases, see the JSR 308 spec, appendix A.3, "Receivers" [1]. (The 
text there has not changed in recent revisions of the spec.)

Alex

[1] 
http://types.cs.washington.edu/jsr308/specification/java-annotation-design.html#type-annotation-use-cases

On 11/28/2012 4:52 PM, Jonathan Gibbons wrote:
> The following code is in one of the test cases in
> /jdk8/type-annotation/langtools/test/tools/javac/annotations/typeAnnotations/newlocations.
>
>
> Is this legal? It looks suspicious for having annotations on the type
> parameter X in test3 and test 4.   Surely, the type of the receiver
> should be  exactly as declared after "class", and not with any extra
> annotations. What would be a use case where it makes sense to add
> additional annotations in this location?
>
> -- Jon
>
> class Generic1<X> {
>    void test1(Generic1<X> this) {}
>    void test2(@A Generic1<X> this) {}
>    void test3(Generic1<@A X> this) {}
>    void test4(@A Generic1<@A X> this) {}
> }


More information about the type-annotations-dev mailing list