Annotation on Intersectingtype

Mohan Radhakrishnan radhakrishnan.mohan at gmail.com
Wed Jan 22 21:12:53 PST 2014


It was tricky but this works partly.

Annotation [[]] [java.lang.String&java.io.Serializable]

            TypeVariable tv = (TypeVariable)typeParameterElement.asType();

            TypeMirror tm = tv.getUpperBound();

            System.out.println( "Annotation [" + Arrays.asList(
tm.getAnnotationsByType(com.test.IntersectionType.TypeUse.class)) + "] [" +
tm  + "]");


Thanks,
Mohan



On Thu, Jan 23, 2014 at 12:38 AM, Alex Buckley <alex.buckley at oracle.com>wrote:

> On 1/22/2014 6:11 AM, Jan Lahoda wrote:
>
>> On 01/21/2014 11:08 PM, Alex Buckley wrote:
>>
>>> While "Number & Runnable" is technically an intersection type, there is
>>> no way to get a single IntersectionType mirror for the entire 'extends'
>>> clause of a type parameter. A TypeParameterElement exposes a list of
>>> mirrors. (I suppose it could be a one-element list, where the sole
>>> mirror is an IntersectionType, but that would be a behavioral change
>>> from SE 7.) Literally any other use of an intersection type would be a
>>>
>>
>> I think one can (currently) get an IntersectionType from
>> javax.lang.model.type.TypeVariable.getUpperBound(), if the type variable
>> was declared with multiple (upper) bounds.
>>
>
> I agree that if you have the TypeParameterElement in hand for the
> declaration of type parameter T (which extends Foo & Bar), the API lets you
> call asType() to get the TypeVariable mirror, and hence getUpperBound()
> which may return an IntersectionType mirror.
>
> But this approach is rather subtle, because the sense of TypeVariable is
> that it mirrors a type variable at a use site, hence getLowerBound() as
> well as getUpperBound().
>
> Alex
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/type-annotations-dev/attachments/20140123/f6b0809b/attachment.html 


More information about the type-annotations-dev mailing list