Emmm,This problem is hard to describe.so My code is like:
//this class use as parent public abstract class Test { //there is generic function public <T extend Test> function(List<T> param){ } } //this class use as parent public abstract class Test { //there is generic function public <T extend Test> function(List<T> param){ } } If thea class is derived from 'Test', and I call function(List) on it, then the param type can be any of Test's child. but i want paramchildren and is not fixed to be the childchild's class objI'm calling the method on, which actually is what I want to achieve.
A feasible solution is :
public <T extend Test> function(Class<T> clazz,List<T> param){ //check 'this' and clazz,if 'this' class not equal clszz,throw Exception if (this.getClass().equals(clazz)){ throw new Exception(); } } public <T extend Test> function(Class<T> clazz,List<T> param){ //check 'this' and clazz,if 'this' class not equal clszz,throw Exception if (this.getClass().equals(clazz)){ throw new Exception(); } } But is there a better solution?I I think this problem can be solved during compilation instead of runtime. Sorry, my english is not good, But I want to know how to solve it.thanks