java - Generics to prevent Parent class to be as accepted type -


i have situation in have create generic method can accept list of child objects not parent class objects.

say have

class classa {} 

which getting extended by

class classb extends classa {} class classc extends classa {} 
executemethod(list</* either classb or classc not classa */>) 

can achieve using generics?

i'm not sure why can't allow list<? extends classa> try:

<t extends classa> void executemethod(list<? extends t>); //not sure if work worth try. 

or

public interface classx {} public class classa {      void executemethod(list<? extends classx); } public classb extends classa implements classx {} public classc extends classa implements classx {} 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -