Skip to content

Commit f239d89

Browse files
update basics (#186)
1 parent dd6a3d7 commit f239d89

23 files changed

Lines changed: 319 additions & 20 deletions

src/main/java/com/examplehub/basics/Final.java

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.examplehub.basics.constant;
2+
3+
public class FinalExample {
4+
}

src/main/java/com/examplehub/basics/TypeCast.java renamed to src/main/java/com/examplehub/basics/conversion/TypeCast.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.examplehub.basics;
1+
package com.examplehub.basics.conversion;
22

33
public class TypeCast {
44
public static void main(String[] args) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.examplehub.basics.conversion;
2+
3+
public class TypeConversionExample {
4+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.examplehub.basics.function;
2+
3+
public class ModifyFunctionArgs {
4+
static class MyObj{
5+
public int age = -1;
6+
}
7+
8+
public static void modify(int num, String str, Integer integer, int[] array, MyObj obj) {
9+
num = num + 1;
10+
str = "<" + str + ">";
11+
integer = integer + 1;
12+
array[0] = -array[0];
13+
obj.age = -obj.age;
14+
}
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.examplehub.designpatterns.singleton;
2+
3+
public class SingletonExample1 {
4+
private static final SingletonExample1 INSTANCE = new SingletonExample1();
5+
private SingletonExample1(){
6+
7+
}
8+
public static SingletonExample1 getInstance() {
9+
return INSTANCE;
10+
}
11+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.examplehub.designpatterns.singleton;
2+
3+
public class SingletonExample2 {
4+
private static final SingletonExample2 INSTANCE;
5+
6+
static {
7+
/*
8+
* do more work here
9+
*/
10+
INSTANCE = new SingletonExample2();
11+
}
12+
private SingletonExample2(){
13+
}
14+
public static SingletonExample2 getInstance() {
15+
return INSTANCE;
16+
}
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.examplehub.designpatterns.singleton;
2+
3+
public enum SingletonExample3 {
4+
INSTANCE
5+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.examplehub.designpatterns.singleton;
2+
3+
public class SingletonExample4 {
4+
private static SingletonExample4 INSTANCE;
5+
6+
private SingletonExample4(){
7+
}
8+
9+
public static SingletonExample4 getInstance() {
10+
if (INSTANCE == null) {
11+
INSTANCE = new SingletonExample4();
12+
}
13+
return INSTANCE;
14+
}
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.examplehub.designpatterns.singleton;
2+
3+
public class SingletonExample5 {
4+
private static SingletonExample5 INSTANCE;
5+
6+
private SingletonExample5(){
7+
}
8+
9+
public static SingletonExample5 getInstance() {
10+
if (INSTANCE == null) {
11+
synchronized (SingletonExample5.class) {
12+
if (INSTANCE == null) {
13+
INSTANCE = new SingletonExample5();
14+
}
15+
}
16+
}
17+
return INSTANCE;
18+
}
19+
}

0 commit comments

Comments
 (0)