Well, I tried the "clone" approach and it didn't work...
//////////////////////////////////////////////////////////////////
class X extends Object implements Cloneable {
public X clone() {
return this.clone();
}
}
//////////////////////////////////////////////////////////////
class Factory<T extends X> {
T base;
public Factory(T base) {
this.base = base;
}
public T getNew() {
return (T) base.clone();
}
}
///////////////////////////////////////////////////////
// one uses this generic factories like this...
...
private static doIt() {
Factory<X> obj = new Factory<X>(new X());
X other = obj.getNew();
}
|