Annotation on Intersectingtype

Alex Buckley alex.buckley at
Wed Jan 22 11:08:57 PST 2014

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().


More information about the type-annotations-dev mailing list