Java PrimerMethod Properties in Java
- By by Dirk Riehle
- April 18, 2000
Listing 9. The "StringName newInstance(name)" class method of StringName.
public class StringName extends AbstractName {
/**
* sStringNames stores all StringNames retrieved using newInstance
*/
protected static Hashtable sStringNames= new Hashtable();
...
/**
* Returns a pre-existing StringName, if one exists.
* Creates a new StringName and stores it, if none exists.
* @methodtype factory
* @methodproperties class
*/
public static StringName newInstance(String name) {
StringName sn= (StringName) sStringNames.get(name);
if(sn == null) {
sn= new StringName(name);
sStringNames.put(name, sn);
}
return sn;
}
...
}