The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 Reflection on Tiger
Subject:  A generic Factory (2)
Date:  2004-10-14 23:49:05
From:  carlosayam
Response to: A generic Factory


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();
}

 Feed java.net RSS Feeds