mercredi 19 août 2015

Why does Java have int.class? Why is it equal to Integer.class? [duplicate]

This question already has an answer here:

In Java, int is a primitive type (which I assume means it is not a class). Then, what is the logic behind having int.class? Why does it have a corresponding class object?

Also, why does int.class equal to Integer.class? When I run the following code:

System.out.println(Integer.TYPE == int.class);                                  

The system outputs

true

How can I differentiate if an object is a primitive type(i.e int) or its corresponding wrapper class (i.e Integer)?





Aucun commentaire:

Enregistrer un commentaire