Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Mmmh, I don't think I got the issue. Could you try to rephrase? Commented Feb 6, 2021 at 17:39
  • I created a class use as parent ,the class hava a generic function ,look like : ``` public class Test { /** there is generic function,'List' just a example, * (maybe is a Any class has generic.To simplify the * problem, use list as an example.) * A class extending 'Test',and call this function, * param can be 'Test' list , or any 'Test' child * list. This is not i want, I expect param only be * the corresponding child list */ public <T extend Test> function(List<T> param){ } } ``` Commented Feb 7, 2021 at 2:41
  • Assume that both types inherit Test ``` public class Test1 extend Test{ } ``` ``` public class Test2 extend Test{ } ``` try call Test1 obj function : java //params List<Test> testList; List<Test1> test1List; List<Test2> test2List; Test1 test = new Test1(); / ** * it's okay for params is testList * it's okay for params is test2List * I expect param can only be test1List * / test1.function(test1List); Commented Feb 7, 2021 at 2:42
  • I think it is achievable,because child have specific type,and the function not static, so has 'this'. I thought of pseudo code : java public <T extend this.class> function(List<T> param){ } Commented Feb 7, 2021 at 2:42