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 means actor or subtypes of actor.
  • class<? extends actor>[] means array of class<t> objects each object represents class either actor or subtype of actor.
  • class<? extends class<? extends actor>[]> represents the class of array of class objects, each object either actor 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

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -