Java 17 버전
벨로그에 국내 jdk 버전에 대해 재밌는 이야기를 한 것
한 번 읽어보시라 재밌는글 입니다
참고: https://www.blog-dreamus.com/post/zgc%EC%97%90-%EB%8C%80%ED%95%B4%EC%84%9C
JDK 11부터 공개되었고, STW로 인한 성능저하를 개선하기 위한 목적을 가지고 오라클에서 개발하였다.
https://wiki.openjdk.org/display/zgc/Main
https://github.com/openjdk/zgc
java -XX:+UseZGC -jar Application.java
// 변경 전
Set<String> set = new HashSet<>();
set.add("a");
set.add("b");
// 변경 후
Set<String> set = Set.of("a", "b", "c");
// 변경 전
List<String> list = new ArrayList<>();
list.add("a");
list.add("b");
list.add("c");
list.add("d");
list.add("e");
// 변경 후
List<String> list = List.of("a", "b", "c", "d", "e");
// 변경 전
Map<String, String> map = new HashMap<>();
map.put("J","a");
map.put("B","b");
map.put("Z","c");
map.put("M","d");
map.put("E","e");
// 변경 후
Map<String, String> map
= Map.of(
"J", "a",
"B", "b",
"Z", "c",
"M", "d",
"E", "e");
http://www.reactive-streams.org/
https://www.baeldung.com/spring-webflux
var strData = "a";
var doubleData = 1.5;
var intData = 100;
var datas = List.of(strData, doubleData, intData);
for (var data : datas) {
...
}
public static void isBlankMethod() {
"".isBlank(); // Output :: true
"abc".isBlank(); // Output :: false
}
public static void linesMethod() {
"a\nb\nc\nd\ne".lines().toArray();
// Output :: [a, b, c, d, e]
}
public static void stripMethod() {
" abc ".strip(); // Output :: (abc)
" abc ".stripLeading(); // Output :: (abc )
" abc ".stripTrailing(); // Output :: ( abc)
}
public static void repeatMethod() {
"aaa ".repeat(3); // Output :: aaa aaa aaa
}
JDK 15부터 정식 지원하는 새로운 기능
“”” {String 문자열 } “””
형식을 이용해 Java 문자열을 보다 가독성있게 작성하도록 도와준다
String message = """
[
{
"type": "header",
"text": {
"type": "plain_text",
"text": "%s :mag:",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*API*: %s\\n*remoteIP*: %s\\n*serverIP*: %s"
}
},
{
"type": "divider"
}
]
""".formatted(caller, apiName, remoteIP, serverIP);
var randomNames = new String [] {"a", "b", "c", "d", "e"}[(int) (Math.random() * 5)];
String name = switch(randomNames) {
case "a", "b" -> {
System.out.println("Me!");
yield "a";
}
case "b", "b" -> "b";
case "c" -> "c";
case "d" -> "d";
case "e" -> "e";
default -> "What's your name";
};
Record Data Class란, JDK 14 버전부터 공개된 Immutable 객체를 생성하는 새로운 유형의 클래스이다.
Record 선언을 하게 되면 기존 toString, equals, hashCode 메소드를 자동으로 구현해주며, 모든 인스턴스 필드를 초기화해주는 생성자가 생성이 된다.
Immutable 객체이기 때문에 모든 값은 생성자를 통해 설정되어야 한다
DTO와 같은 Data Object 용도로 활용 시 보다 편리하고 간결하게 구분할 수 있다.
ModelMapper 라이브러리는 setter를 통해 값을 설정하기 때문에 Record Class를 ModelMapper에 사용할 수 없는 것으로 확인되었다.
Record Class는 상속이 불가능하다. (모든 필드는 private final로 선언되어있다.)
public record RecordUserData(String name, int weight) {
}
...
RecordUserData userRecord = new RecordUserData("a", 110);
// Output :: a
System.out.println(userRecord.name());
// Output :: 110
System.out.println(userRecord.weight());
// Output :: false
System.out.println(userRecord.equals(new RecordUserData("b", 90)));
// Output :: RecordUserData[name=a, weight=110]
System.out.println(userRecord);