Skip to content

Commit fdfa94f

Browse files
committed
problem02 单例
1 parent ad86066 commit fdfa94f

File tree

5 files changed

+68
-76
lines changed

5 files changed

+68
-76
lines changed

swordForOffer/pom.xml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
5-
<groupId>com.netease.yangrubing</groupId>
6-
<artifactId>swordForOffer</artifactId>
7-
<version>0.0.1-SNAPSHOT</version>
8-
<packaging>jar</packaging>
9-
10-
<name>swordForOffer</name>
11-
<url>http://maven.apache.org</url>
12-
13-
<properties>
14-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
</properties>
16-
17-
<dependencies>
18-
<dependency>
19-
<groupId>junit</groupId>
20-
<artifactId>junit</artifactId>
21-
<version>3.8.1</version>
22-
<scope>test</scope>
23-
</dependency>
24-
</dependencies>
25-
</project>
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.netease.yangrubing</groupId>
6+
<artifactId>swordForOffer</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>swordForOffer</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>junit</groupId>
20+
<artifactId>junit</artifactId>
21+
<version>4.7</version>
22+
<scope>test</scope>
23+
</dependency>
24+
</dependencies>
25+
</project>

swordForOffer/src/main/java/com/netease/yangrubing/swordForOffer/App.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package problem02;
2+
3+
/**
4+
* 单例模式,采用静态类的实现方式
5+
* @author bjyangrubing
6+
*
7+
*/
8+
public class SingletonClass
9+
{
10+
/**set the construtor private*/
11+
private SingletonClass()
12+
{
13+
}
14+
15+
private static class SingletonHolder
16+
{
17+
private static final SingletonClass INSTANCE = new SingletonClass();
18+
}
19+
20+
public static SingletonClass newInstance()
21+
{
22+
return SingletonHolder.INSTANCE;
23+
}
24+
}

swordForOffer/src/test/java/com/netease/yangrubing/swordForOffer/AppTest.java

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package problem02;
2+
3+
import org.junit.Test;
4+
5+
import junit.framework.Assert;
6+
import problem02.SingletonClass;
7+
8+
public class SingletonClassTest
9+
{
10+
@Test
11+
public void test()
12+
{
13+
SingletonClass singletonClass1 = SingletonClass.newInstance();
14+
15+
SingletonClass singletonClass2 = SingletonClass.newInstance();
16+
17+
Assert.assertEquals(singletonClass1, singletonClass2);
18+
}
19+
}

0 commit comments

Comments
 (0)