File tree 7 files changed +150
-5
lines changed
src/main/java/com/di1shuai/java14
7 files changed +150
-5
lines changed Original file line number Diff line number Diff line change 109
109
- ZGC 增强 - 释放未使用内存
110
110
- SocketAPI 重构
111
111
112
- ### JDK 14
112
+ ### [ JDK 14] ( java-14 )
113
113
114
114
---
115
115
116
- - instanceof模式识别
117
- - Records
118
- - 启用Parallel Scavenge+Serial GC组合
119
- - 删除CMS GC
116
+ - [ instanceof模式识别 增强] ( java-14/src/main/java/com/di1shuai/java14/instance/InstanceOfDemo.java )
117
+ - [ Record 类型] ( java-14/src/main/java/com/di1shuai/java14/record/RecordDemo.java )
118
+ - [ 异常信息提示改进] ( java-14/src/main/java/com/di1shuai/java14/nullexception/NullPointerExceptionDemo.java )
119
+ - 其他
120
+ - G1 的 NUMA 可识别内存分配
121
+ - 删除 CMS GC
122
+ - GC 支持 MacOS 和 Windows 系统
Original file line number Diff line number Diff line change
1
+ ### JDK 14
2
+
3
+ ---
4
+
5
+ - [ instanceof模式识别 增强] ( src/main/java/com/di1shuai/java14/instance/InstanceOfDemo.java )
6
+ - [ Record 类型] ( src/main/java/com/di1shuai/java14/record/RecordDemo.java )
7
+ - [ 异常信息提示改进] ( src/main/java/com/di1shuai/java14/nullexception/NullPointerExceptionDemo.java )
8
+ - 其他
9
+ - G1 的 NUMA 可识别内存分配
10
+ - 删除 CMS GC
11
+ - GC 支持 MacOS 和 Windows 系统
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5
+ <parent >
6
+ <artifactId >java-versions</artifactId >
7
+ <groupId >com.di1shuai</groupId >
8
+ <version >1.0-SNAPSHOT</version >
9
+ </parent >
10
+ <modelVersion >4.0.0</modelVersion >
11
+
12
+ <artifactId >java-14</artifactId >
13
+ <build >
14
+ <plugins >
15
+ <plugin >
16
+ <groupId >org.apache.maven.plugins</groupId >
17
+ <artifactId >maven-compiler-plugin</artifactId >
18
+ <configuration >
19
+ <source >15</source >
20
+ <target >15</target >
21
+ <compilerArgs >--enable-preview</compilerArgs >
22
+ </configuration >
23
+ </plugin >
24
+ </plugins >
25
+ </build >
26
+
27
+ <properties >
28
+ <maven .compiler.source>14</maven .compiler.source>
29
+ <maven .compiler.target>14</maven .compiler.target>
30
+ </properties >
31
+
32
+ </project >
Original file line number Diff line number Diff line change
1
+ package com .di1shuai .java14 .instance ;
2
+
3
+ /**
4
+ * @author Shea
5
+ * @date 2021-01-22
6
+ * @description
7
+ */
8
+ public class InstanceOfDemo {
9
+
10
+ public static void main (String [] args ) {
11
+ Object obj = " hello Java 14 " ;
12
+ // < 14
13
+ if (obj instanceof String ) {
14
+ System .out .println (((String ) obj ).strip ());
15
+ }
16
+
17
+ // 14
18
+ if (obj instanceof String str ) {
19
+ System .out .println (str .strip ());
20
+ }
21
+
22
+
23
+ }
24
+
25
+ }
Original file line number Diff line number Diff line change
1
+ package com .di1shuai .java14 .nullexception ;
2
+
3
+ /**
4
+ * @author Shea
5
+ * @date 2021-01-23
6
+ * @description
7
+ *
8
+ * before 14
9
+ *
10
+ * java.lang.NullPointerException
11
+ * at com.di1shuai.java14.nullexception.NullPointerExceptionDemo.main(NullPointerExceptionDemo.java:21)
12
+ *
13
+ *
14
+ * 14 默认开启 -XX:+ShowCodeDetailsInExceptionMessages
15
+ *
16
+ * Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.toString()" because "str" is null
17
+ * at com.di1shuai.java14.nullexception.NullPointerExceptionDemo.main(NullPointerExceptionDemo.java:12)
18
+ *
19
+ */
20
+ public class NullPointerExceptionDemo {
21
+
22
+ public static void main (String [] args ) {
23
+ String str = null ;
24
+ try {
25
+ str .toString ();
26
+ }catch (NullPointerException e ){
27
+ e .printStackTrace ();
28
+ }
29
+
30
+ }
31
+
32
+ }
Original file line number Diff line number Diff line change
1
+ package com .di1shuai .java14 .record ;
2
+
3
+ /**
4
+ * @author Shea
5
+ * @date 2021-01-22
6
+ * @description
7
+ *
8
+ *
9
+ */
10
+ public class RecordDemo {
11
+
12
+ public static void main (String [] args ) {
13
+ Student s = new Student ("shea" ,18 );
14
+ System .out .println (
15
+ """
16
+ getName -> %s
17
+ getAge -> %s
18
+ toString -> %s
19
+ hashCode -> %s
20
+ """ .formatted (
21
+ s .name (),
22
+ s .age (),
23
+ s .toString (),
24
+ s .hashCode ()
25
+ )
26
+ );
27
+ }
28
+
29
+
30
+ }
31
+
32
+ /**
33
+ * 构造方法
34
+ * hashCode() 方法
35
+ * euqals() 方法
36
+ * toString() 方法
37
+ * 类对象被final 关键字修饰,不能被继承。
38
+ */
39
+ record Student (String name ,int age ){
40
+
41
+ }
Original file line number Diff line number Diff line change 18
18
<module >java-10</module >
19
19
<module >java-12</module >
20
20
<module >java-13</module >
21
+ <module >java-14</module >
21
22
</modules >
22
23
23
24
<dependencyManagement >
You can’t perform that action at this time.
0 commit comments