Further checking seems to imply that the answer is NO.
Since the following program is still rejected. So the cast issue a know bug
? Or is the spec being modified to reflect this behavior ?
import java.util.List;
import java.util.Map;
public class X {
public static void main(String[] args) {
Object o2 = new List<? extends Object>[3];
}
}
Playing with unchecked cast semantics, I noticed a strange behavior in
javac (latest 1.5 and 1.6).
I was expecting [2] to issue an unchecked cast warning, according to JLS
5.5; since "List<? extends Object>" doesn't meet the criteria that:
"All of the type arguments (��4.5.1) of T are unbounded wildcards."
Did the spec change to consider "List<?>" the same as "List<? extends
Object>" ? i.e. unbounded or bounded by a no-op bound (same as formal
bound).
I would agree they are essentially the same, but I am curious about the
official saying here.
import java.util.List;
public class X {
public static void main(String[] args) {
Object object = null;
foo((List<? extends String>)object); //[1]
foo((List<? extends Object>)object); //[2]
foo((List<?>)object); //[3]
}
public static void foo(List<?> list) {
}
}