Aurasphere Aurasphere - 3 months ago 12
Java Question

Check javax.lang.model.type.TypeMirror is a primitive type

Is there any way I can check that a

javax.lang.model.type.TypeMirror
is a primitive type? I've tried
instanceof PrimitiveType
but this always yields true since
PrimitiveType
extends TypeMirror.

Thank you for the help.

Answer

Per https://docs.oracle.com/javase/7/docs/api/javax/lang/model/type/TypeMirror.html

To implement operations based on the class of an TypeMirror object, either use a visitor or use the result of the getKind() method. Using instanceof is not necessarily a reliable idiom for determining the effective class of an object in this modeling hierarchy since an implementation may choose to have a single object implement multiple TypeMirror subinterfaces.

Try calling getKind() rather than instanceOf.