Why does subclass still need a casting to access value from his Generic
parent's properties ? Any particular reason ? have a look :
class a<U, T> {
public U u;
public T t;
public a(U u, T t) {
this.u = u;
this.t = t;
}
public U getU(){
return u;
}
}
class b extends a {
public b(String u, Integer t) { super(u, t); }
// Here I call b's parent method where casting occurs
public String get(){
return (String) getU(); // Here's the cast
}
}
I know that the type returned by super.getU()
is U
, but Isn't b
inherited from a
which means a
's properties will be visible to its children classes!? Plus superclass' constructor had been refered by super(11111,"aString"); ? Isn't it enough to tell b
's parent that "I'm your child passing an Integer
& a String
" , it looks to me like there is no relation between class "a" and class "b"
*UDPATE : code typos had been fixed ,sorry it happened because i typed in hurry.