Java generics SuppressWarnings("unchecked") mystery
- by Johannes Ernst
Why does code alternative(1) compile without warnings, and code alternative(2) produce an "unchecked cast" warning?
Common for both:
class Foo<T> {
Foo( T [] arg ) {
}
}
Alternative (1):
class Bar<T> extends Foo<T> {
protected static final Object [] EMPTY_ARRAY = {};
@SuppressWarnings("unchecked")
Bar() {…