I working on a java Project,
My teacher sent me an example of a code and I saw something I don't know,
But his explanation wasn't the best.
Can someone explain to me more about Class
?
When to use and why to use
I working on a java Project,
My teacher sent me an example of a code and I saw something I don't know,
But his explanation wasn't the best.
Can someone explain to me more about Class
?
When to use and why to use
Class<?>
means any class type.
For example, Integer.class
is a type of Class<Integer>
, Double.class
is a type of Class<Double>
.
If a type of variable is Class<?>
, then the variable can be set to any class type.
Class<Integer> clazz = Integer.class (0)
Class<Integer> clazz = Double.class (x)
Class<?> clazz = Integer.class (0)
Class<?> clazz = Double.class (0)
Class<?>[]
getClasses()
Returns an array containing Class objects representing all the public classes and interfaces that are members of the class represented by this Class object.
From Oracle Documantation :
http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html