Search code examples
javagenericsbounded-wildcardbounded-types

Bounded Wildcards in Java


This is not fine

     List<List<? extends Number>> a;
     List<List<Integer>> b;
     a = b;

This is fine

     List<? extends Number> c;
     List<Integer> d;
     c = d;

How can make it compile first one?


Solution

  • You could use this:

    List<? extends List<? extends Number>> a;
    List<List<Integer>> b;
    a = b;