- ★★Java質問・相談スレッド172★★ [転載禁止]©2ch.net
756 :デフォルトの名無しさん[sage]:2015/04/01(水) 03:35:20.24 ID:uyRJR5DZ - public class SingletonTest {
private final int foo; private static SingletonTest instance = null; private SingletonTest(int foo) { this.foo = foo; //←これ } public static SingletonTest newInstance(int foo) { if (instance != null) throw new AlreadyExistedException("already existed"); return instance = new SingletonTest(foo); } public static SingletonTest getInstance() { return (instance == null) ? newInstance(1) : instance; } }
|
|