0

This may seem a dumb question (as it could be very project specific) but in this case it's general enough:

I'm running a piece of code which gives the ClassCastException, with the error message I wrote as title. Here the mentioned cast is from an object of type java.lang.reflect.Type to Class<?>.

Apart from primitive types, which type in Java is not a class?

Thanks for your answers

2
  • 3
    Please post the line of code and original error Jan 29, 2013 at 19:14
  • All of them. Class is itself a class that inherits from Object, so the usual rules apply.
    – SJuan76
    Jan 29, 2013 at 19:15

2 Answers 2

5

A Class is a Type but a Type isn't necessary a Class, since Class implements Type.

Basically, your myType could also be any of the implementing classes of the interfaces GenericArrayType, ParameterizedType, TypeVariable or WildcardType, since they all extend the Type interface.

Try to print myType.getClass() to see the type you mean: you'll get Class<TheSaidType>.

2

From the Javadoc for Type you can see it has a number of implementing types.

All Known Subinterfaces:
    GenericArrayType, ParameterizedType, TypeVariable<D>, WildcardType

All Known Implementing Classes:
    Class 

Th sub-interfaces are implemented using internal data structure classes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.