로딩
요청 처리 중입니다...

[자바] java 21 switch null check

 [자바] java 21 switch null check

기존 switch 문의 경우 null 체크를 if문을 사용 하였다. private static void testSwitch(String str) { if (str == null) { System.out.println("Null!"); return; } switch (str) { case "A", "B" -> System.out.println("Hello"); default -> System.out.println("Ok"); } } java 21 부터는 switch 문에서 null 체크가 가능하다. private static void TestSwitch(String str) { switch (str) { case null -> System.out.println("Null!")

; case "A", "B" -> System.out.println("Hello"); default -> System.out.println("Ok"); } } 참고링크: https://openjdk.org/jeps...