Generic method with parameters vs. non-generic method with wildcards

前端 未结 4 1657
执笔经年
执笔经年 2021-02-07 05:15

According to this entry in the Java Generics FAQ, there are some circumstances where a generic method has no equivalent non-generic method that uses wildcard types. According

4条回答
  •  青春惊慌失措
    2021-02-07 05:58

    These are not quite the same:

    > void f(Class x) {}
    void g(Class> x) {}
    

    The difference is that g accepts a "Class of unknown that implements Iterable of unknown", but ArrayList is constrained implementing Iterable, not Iterable, so it doesn't match.

    To make it clearer, g will accept Foo implements Iterable, but not AraryList implements Iterable.

提交回复
热议问题