A.java
public class A<E> {
Class cClass;
public A(Class rClass) {
this.cClass = rClass;
}
public E get() throws IllegalAccessException, InstantiationException {
return (E) this.cClass.newInstance();
}
}
A1.java
public class A1 extends A {}
I am trying to design a class A as generic and class A1 is a sub class of class A. Object creation should look something like this.
A<A1> a1 = new A<>();
I want provide a way that no one will create an object like this
A<B1> a1 = new A<>();
where class B1 is not a subclass of A.
How can i resolve this? Error
error: constructor Operation in class A<E> cannot be applied to given types