Generic collection & wildcard in java

前端 未结 3 996
傲寒
傲寒 2021-01-21 05:18

I am having problems getting my head around generics in the following situation, see inline comments below for my questions:

public void exampleMethod() {
    //         


        
3条回答
  •  清歌不尽
    2021-01-21 05:57

    You don't need wildcards here In your case it would suffice to say

    Set test;
    

    And you can then put any subclass of AbstractGroup into the set.

    Also, it doesn't look like you're initializing test in your code above.

提交回复
热议问题