Reputation: 481
I was hoping that someone could tell me why java has java.lang.reflect.Type
, when everything already inherits from Object
?
Could someone please give an example of a case where I would need to use a Type
and not an Object
?
Upvotes: 6
Views: 209
Reputation: 321
'Object' is the supertype for all classes, 'Class' is a class defining a class and 'Type' is a supertype that also covers primitive types (int, boolean, etc).
Upvotes: 0
Reputation: 115338
Object
is a base class for all java classes. Type
is just an tag interface for all classes that represent types. It was introduced in java 1.5 because prior to java 1.5 there was no classes that represent java type except java.lang.Class
. Then when generics were introduced there was a need to create some general abstraction common for Class
, generic array etc. So they defined interface Type
.
Upvotes: 9