This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| language:java [2026/08/31 13:52] – ledyx | language:java [2026/09/01 06:04] (current) – Pattern Matching ledyx | ||
|---|---|---|---|
| Line 22: | Line 22: | ||
| * StackWalker -> Stack을 훑는 기능. Debug할 때 좋을 듯. | * StackWalker -> Stack을 훑는 기능. Debug할 때 좋을 듯. | ||
| * 내부 문자열 처리 방식 개선으로 메모리 절약. 기존에는 UTF-16 char 배열이었지만 문자에 따라 1byte 혹은 2byte가 필요한지에 따라 다르게 저장 -> isLatin() | * 내부 문자열 처리 방식 개선으로 메모리 절약. 기존에는 UTF-16 char 배열이었지만 문자에 따라 1byte 혹은 2byte가 필요한지에 따라 다르게 저장 -> isLatin() | ||
| - | * G1GC가 default GC. 이전 Parallel GC가 메모리를 물리적으로 나누었다면, | + | |
| * OOM 발생시 사용할 수 있는 옵션 두 가지 추가 | * OOM 발생시 사용할 수 있는 옵션 두 가지 추가 | ||
| * ExitOnOutOfMemoryError | * ExitOnOutOfMemoryError | ||
| Line 34: | Line 34: | ||
| * G1GC 성능 개선 | * G1GC 성능 개선 | ||
| - | == 11 == | + | == 11(LTS) == |
| + | * var에 람다식 매개변수에 적용 가능 | ||
| + | * String, Predicate 기능 추가 | ||
| + | * Files 클래스에 파일 전체< | ||
| + | * 새로운 Http Client 모듈 | ||
| + | * ZGC(experimetnal) -> 25에서 정식 GC로 승격 | ||
| + | |||
| + | == 12 ~ 17(LTS) == | ||
| + | |||
| + | === 15 === | ||
| + | |||
| + | ==== Text Block ==== | ||
| + | **여러 줄에 걸친 문자열**을 만들기 위한 새로운 문법 | ||
| + | |||
| + | 12에서 preview였다가 15에서 정식 기능으로 승격 | ||
| + | |||
| + | <sxh java> | ||
| + | // """ | ||
| + | // \를 사용하면 개행 제거 | ||
| + | // 들여쓰기도 가능 | ||
| + | String str = """ | ||
| + | A | ||
| + | BC | ||
| + | DEF""" | ||
| + | </ | ||
| + | |||
| + | === Switch Expression 개선 === | ||
| + | |||
| + | 12에서 preview였다가 14에서 정식 기능으로 승격 | ||
| + | |||
| + | <sxh java> | ||
| + | private String calculateTestGrade1(int score) { | ||
| + | return switch (score) { | ||
| + | case 5: | ||
| + | yield " | ||
| + | case 4, 3: | ||
| + | yield " | ||
| + | case 2: | ||
| + | yield " | ||
| + | default: | ||
| + | yield " | ||
| + | }; | ||
| + | } | ||
| + | | ||
| + | private String calculateTestGrade2(int score) { | ||
| + | return switch (score) { | ||
| + | case 5 -> " | ||
| + | case 4, 3 -> " | ||
| + | case 2 -> { | ||
| + | System.out.println(" | ||
| + | yield " | ||
| + | } | ||
| + | default -> " | ||
| + | }; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== ' | ||
| + | |||
| + | 14에서 preivew였다가 16에서 정식 기능으로 승격 | ||
| + | |||
| + | <sxh java> | ||
| + | public String say(Animal animal) throws IllegalAccessException { | ||
| + | if (animal instanceof Dog dog) { | ||
| + | return dog.bark(); | ||
| + | } else if (animal instanceof Cat cat) { | ||
| + | return cat.purr(); | ||
| + | } | ||
| + | |||
| + | throw new IllegalAccessException(); | ||
| + | } | ||
| + | | ||
| + | // 아래처럼 부정인 경우 Scope가 괄호 밖까지 확장 가능 | ||
| + | public String sayIfDog(Animal animal) throws IllegalAccessException { | ||
| + | if (!(animal instanceof Dog dog)) { | ||
| + | throw new IllegalAccessException(); | ||
| + | } | ||
| + | |||
| + | return dog.bark(); | ||
| + | } | ||
| + | |||
| + | |||
| + | public interface Animal { | ||
| + | } | ||
| + | |||
| + | public static class Dog implements Animal { | ||
| + | public String bark() { | ||
| + | return "Dog barking..."; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public static class Cat implements Animal { | ||
| + | public String purr() { | ||
| + | return "Cat purring..."; | ||
| + | } | ||
| + | } | ||
| + | </ | ||