Consider the following code:
import java.util.ArrayList;
import java.util.List;
public class UnboundedWildcardProblem {
public static void main(String[] args) {
List<?> a = new ArrayList();
List<? extends Object> b = new ArrayList();
}
}
The creation of List<?>
doesn't produce any warnings, but the creation of List<? extends Object>
produces an unchecked warning:
Warning: java: unchecked conversion
required: java.util.List<? extends java.lang.Object>
found: java.util.ArrayList
I searched for possible reasons and found some discussions:
List<?> vs List<? extends Object>
What's the difference between <?> and <? extends Object> in Java Generics?
But after reading these discussions it seems to me that List<?>
and List<? extends Object>
are the same thing.
So, what is the reason for such compiler behaviour?
EDIT:
The single flag used for compilation was an Xlint:unchecked flag.