Following lines:
Class<Integer> clazzInteger = Integer.class;
Class<Integer> clazzInt = int.class;
Are valid and will compile/run even when:
if(clazzInt.equals(clazzInteger)) {
System.out.println("clazzInt equals clazzInteger");
}else {
System.out.println("clazzInt and clazzInteger are not equal");
}
Will print clazzInt and clazzInteger are not equal
. But Class<int> clazzInt = int.class;
do not work of course.
So why this analogy cannot be applied to array types?
Class<int[]> clazzIntArray = int[].class;
Class<Integer[]> clazzIntArray = int[].class; // type mismatch:
//cannot convert from Class<int[]> to Class<Integer[]>
But
Class<int[]> clazzIntArray = int[].class; // this is ok
I'm now baffled why Class<Integer[]> clazzIntArray = int[].class
is invalid? What Class<int[]>
means? And why the analogy between array and non array types does not work?