Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does java have Type when it already has Object?

Tags:

java

types

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?

like image 830
Jay Smith Avatar asked May 13 '13 18:05

Jay Smith


1 Answers

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.

like image 188
AlexR Avatar answered Oct 25 '22 03:10

AlexR