Annotation on Intersectingtype

Alex Buckley alex.buckley at oracle.com
Mon Jan 27 10:55:58 PST 2014


You can't apply an annotation to the intersection type itself. 
jx.l.m.t.IntersectionType is merely being used to model everything after 
the 'extends' token in the type parameter declaration, as it lets you 
access the bounds via getBounds() in a different way than the "obvious" 
path, TypeParameterElement.getBounds(). Unfortunately, I expect the bug 
will still preclude access to annotations on the bounds, how ever those 
bounds are accessed.

Alex

On 1/24/2014 10:14 PM, Mohan Radhakrishnan wrote:
> I am confused.
>
> |//Intersection type|
> |||class| |Test<T ||extends| |String &
> ||@IntersectionType||.TypeUse(value = ||2||) Serializable>{|
> |||}|
> |
> |
> How do I apply an annotation on the intersection type itself instead of
> on individual bounds ? The code I sent earlier doesn't print the
> annotation which might be the bug you are mentioning. It prints the
> intersection type only.
>
> Thanks,
> Mohan
>
>
> On Sat, Jan 25, 2014 at 2:08 AM, Alex Buckley <alex.buckley at oracle.com
> <mailto:alex.buckley at oracle.com>> wrote:
>
>     On 1/23/2014 8:24 PM, Mohan Radhakrishnan wrote:
>
>         Ok. I understand I have to get each bound and get the annotation
>         applied
>         on it. There is no annotation applied on the intersection type
>         itself.
>
>
>     Well, in theory you should be able to get the bounds' mirrors
>     individually, and read their annotations, but it doesn't currently
>     work. So, you have to get the intersection type's mirror
>     (representing all the bounds in one go) and read the annotations
>     from there - you even sent code yesterday showing how to do that. We
>     are working on cleaning up the type annotation reflection for a JDK
>     8 update release.
>
>
>         Did you mean  something like this by cast?
>
>         |Serializable f2|
>         |= (BiPredicate<String,String> & Serializable)|
>         |(s,t) -> s.equalsIgnoreCase(t);|
>
>
>     Yes. The use of an intersection type in a cast is brand new in SE 8.
>     Although, I guess the Language Model doesn't expose individual
>     expressions like casts, so the javadoc would have to be worded
>     carefully.
>
>     Alex
>
>


More information about the type-annotations-dev mailing list