我熟悉静态变量和单例,但我没有看到任何关于此的信息:
public class MyImmutableClass {
private final String string;
public static final MyImmutableClass getInstance(String s) {
if( a MyImmutableClass already exists with that string as its field)
return (that instance);
else
return a new instance;
}
...
}
不能存在 MyImmutableClass 的重复项。这是否有意义,如果是,您将如何实施?