class A<E>{
}
class B<E> extends A{
}
public class WildInDeclare<E>{
public static void main(String[] args){
A<Integer> obj = new B<Integer>();
}
}
When I compile the above program I got this error.
Note: WildInDeclare.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
After that I just replace class B<E> extends A{ to class B<E> extends A<E>{ it works fine can you explain why it required to again write A<E> During inheritance with code Example Please.
The second Problem with Inheritance I faced. I update the above code with the follow code.
class A<E>{
public A(E o){
}
}
class B<E> extends A{
public B(){
super(E);
}
}
public class WildInDeclare<E>{
public static void main(String[] args){
A<Integer> obj = new B<Integer>();
}
}
But it is not compiling why? I got the following error.
WildInDeclare.java:8: error: cannot find symbol
super(E);
^
symbol: variable E
location: class B<E>
where E is a type-variable:
E extends Object declared in class B
Note: WildInDeclare.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
How I can pass Parameter to Parent class?
A, which has a generic in it´s class signature. If you leave it outAwill be inherited as rawtype.(how should the compiler automaticly decide for you that the genericEfor classBhas to be used as the generic forAaswell)?A<E>doesn't extendB<String>? The type parameter might be used for something quite different in the subclass.super(E), what isE, it´s not a variable just a type, so the compiler tells you so (what should it pass?)(E) null.