1 Star 0 Fork 3

serv/JavaDesigner

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
TestB.java 1.29 KB
Copy Edit Raw Blame History
serv authored 2014-04-08 11:42 +08:00 . init
/**
* Test for our Singleton registry
*/
public class TestB {
public static void main(String[] args) {
// First we get a instance from SingletonB
SingletonB instance1 = SingletonB.GetInstance("Sub1");
if(instance1 == null) {
System.out.println("There is no such instance in registry !");
} else {
System.out.println(instance1.getClass());
}
// Then we register a new instance
try {
SingletonB instance2 = new SubSingletonB();
System.out.println("We had created a new instance named \"Sub1\" now");
} catch (SingletonException e) {
System.out.println(e.getMessage());
}
// To get instance again
instance1 = SingletonB.GetInstance("Sub1");
if(instance1 == null) {
System.out.println("There is no such instance in registry !");
} else {
System.out.println(instance1.getClass());
}
// Finally we create a new instance again
try {
SingletonB instance3 = new SubSingletonB();
System.out.println("We had created a new instance named \"Sub1\" now");
} catch (SingletonException e) {
System.out.println(e.getMessage());
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/feike/JavaDesigner.git
git@gitee.com:feike/JavaDesigner.git
feike
JavaDesigner
JavaDesigner
master

Search