The foo
method in following example gives us a warning, while bar
not?
public class X {
static class Y {}
static class Z extends Y {}
Y y = new Y();
<T extends Y> T foo() {
return (T) y; // warning - Unchecked cast from X.Y to T
}
Z bar() {
return (Z) y; // compiles fine
}
}