Consider the following Java Generics layout where I would expect ItemList to have a compatible interface to List:
public interface ItemList<T extends Item> extends List<T> {}
public interface Item {}
public interface List<T> {}
public static class Test<T extends Item> {
public void foo(ItemList<T> fizz) {
// T extends B
// fizz is A<T extends B> extends C<T extends B>
// therefore, is fizz not always compatible with C<B>?
// bar(fizz); error?
bar((List<Item>) fizz); // allowed, but unchecked cast warning?
}
private void bar(List<Item> buzz) {}
}
I.e. Why am I unable to pass fizz
to the bar
method and why am I being warned of an unchecked cast? Is this guaranteed to be a safe cast, or is the warning a legitimate issue?