This question already has an answer here:
- What does int.class mean 3 answers
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