Why does java have a Type when it already has an Object?

I was hoping someone would tell me why java has java.lang.reflect.Type when everything is already inheriting from Object ?

Can someone please give an example of the case when I will need to use Type , and not Object ?

+6
source share
2 answers

Object is the base class for all java classes. Type is just a tag interface for all classes representing types. It was introduced in java 1.5 because before java 1.5 there were no classes that represent the java type except java.lang.Class . Then, when generics were introduced, it became necessary to create a common abstraction common to Class , a common array, etc. Thus, they defined the Type interface.

+9
source

“Object” is the supertype for all classes, “Class” is the class that defines the class, and “Type” is the supertype that also encompasses primitive types (int, boolean, etc.).

0
source

Source: https://habr.com/ru/post/944906/


All Articles