I have a class:
public class SomeClass <TView extends View>{
private TView tv;
public SomeClass(View v){
tv=(TView) v; //unchecked cast warning
}
}
View is a concrete class (not abstract, not interface).
Question is
Why do I get an unchecked cast warning, even if TView extends View?
The cast is not enforced at runtime.
Your class post-erasure looks like:
Note that post-erasure, the constructor is casting a value of type
Viewto typeViewsince that is the lower-bound for<TView extends View>.Casting
ViewtoViewdoes not check anything at runtime, which is why you get the warning.