java - Explanation for convoluted generic-type declaration. What does Class<? extends Class<? extends Actor>[]> actually mean? -
imagine have class.
public class actor {...}
and have method needs parameter type of:
class<? extends class<? extends actor>[]>
is possible? not decipher it.
yes. let's work inside out:
? extends actor
meansactor
or subtypes ofactor
.class<? extends actor>[]
means array ofclass<t>
objects each object represents class eitheractor
or subtype ofactor
.class<? extends class<? extends actor>[]>
represents the class of array of class objects, each object eitheractor
or 1 of subtypes.*
here's example should make bit more clear:
//actorclass class<t> object represents actor.class //or of subtypes class<? extends actor> actorclass = actor.class; //classarray array of class<? extends actor> objects, , type //class<? extends actor>[] //you warning unsafe cast here because //cannot create array of generic type, means //rhs type `class[]`. class<? extends actor>[] classarray = new class[] { actorclass, actorclass, actorclass }; //now class of array itself, matches convoluted //expression saw. class<? extends class<? extends actor>[]> classarrayclass = classarray.getclass();
the important thing note here giant expression does not represent class extends array of class<? extends actor>
objects. instead, it represents class of array of class<? extends actor>
objects.
* technically, you can't create array of generic type, means class<? extends actor>[]
class[]
. end class<class[]>
, class represents array of class
objects (i.e., class[].class
).
Comments
Post a Comment