Jay Smith
Jay Smith

Reputation: 481

Why does java have Type when it already has Object?

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

Answers (2)

javadeveloper
javadeveloper

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

AlexR
AlexR

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

Related Questions