I have a class let's call it Creator which contains two instance fields. Those fields belong to a parent class A. In the Creator's constructor I want to pass a child of class A and then to create two objects from that passed type and assign the references to the two fields. How can I do something like that? I don't know how to make this generalization.
EDIT: the class Creator shall only accept types that are children of A or A itself. So not any other general type. AND A does not have a no-argument constructor
So like this, here GeneralClassifier is A and doesn't have a no-argument constructor:
public class TwoLevelClassifier <T> {
private GeneralClassifier firstCl, secondCl;
//The passed type shall *only* be a GeneralClassifier or a child of it
public TwoLevelClassifier( GeneralClassifier cl ) {
firstCl = //create a new classifier that is of the type passed to the constructor
secondCl = //create a new classifier that is of the type passed to the constructor
}
}
I'm not sure, but maybe this feature is called generics in java?