Unbounded wildcards in Java

后端 未结 6 1976
自闭症患者
自闭症患者 2020-12-02 23:55

Is there ever a difference between an unbounded wildcard e.g. and a bounded wildcard whose bound is Object, e.g.

6条回答
  •  广开言路
    2020-12-03 00:15

    From experimentation it seems that, for example, List and List are assignment-compatible both ways, and a method that has a signature using one of them can be overridden with a signature using the other. e.g.,

    import java.util.List;
    
    class WildcardTest {
        public void foo(List bar) {}
    }
    
    class WildcardTest2 extends WildcardTest {
        @Override
        public void foo(List bar) {super.foo(bar);}
    }
    
        

    提交回复
    热议问题