Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 221
Cemo Avatar asked Dec 17 '22 03:12

Cemo


2 Answers

You could use this:

List<? extends List<? extends Number>> a;
List<List<Integer>> b;
a = b;
like image 139
Thomas Avatar answered Jan 02 '23 18:01

Thomas


List<? extends List<? extends Number>> a = null;
List<List<Integer>> b = null;
a = b;
like image 42
Matthijs Bierman Avatar answered Jan 02 '23 19:01

Matthijs Bierman