Today I wrote some heavy reflexive code, and I came across this behavior, I can not explain: why
Type[] types = ((ParameterizedType)m.getGenericReturnType()).getActualTypeArguments();
Class[] c = (Class[])types;
Throw a ClassCastException when repeating the same array and casting each individual element, i.e.
for(Type t : types) {
Class c = (Class)t;
}
succeeds?
I mean, if casting one element into another class is possible, then why can't there be a listing between arrays of the same types?
There is probably a reason, but I cannot find it ...
source
share