Okay this is my first post here so bear with me.. I'm working on a small side project about genetic programming and I'm using generics.
These are small code snippets:
public class BinaryGenome<C extends BinaryEncodeable<C>> {
public BinaryGenome(C encodable){
setGenome(encodable.encode());
setSpecification(encodable);
}
public BinaryGenome(BitSet encoding) {
setGenome(encoding);
//What comes here???
}
}
public interface BinaryEncodeable<C extends BinaryEncodeable<C>> {
public BitSet encode();
public C decode(BitSet encoding);
}
The BinaryGenome represents a genome, it contains the object it represents and the bit representation. I'm able to use the first constructor, but I'm having troubles with the second one. Is it possible to create an object C in the second constructor from the encoding, given that each class implementing BinaryEncodable has a decode method.
I know "new C()" doesn't work because of type errasure but is there some kind of factory I can use?