# JAVA14

아래와 같은 저품격 코딩스타일 지겹죠? `쓰다보면 어느새 IF 수렁이에 빠지는군 하죠.`

```java
if (flag == 1) {
  log.info("didispace.com: 1");
} else if (flag == 2) {
  log.info("didispace.com: 2");
} else if (flag == 3) {
  log.info("didispace.com: 3");
} else if (flag == 4) {
  log.info("didispace.com: 4");
} else {
  log.info("didispace.com: x");
}
```

`그러면 switch로 하면?`

```java
switch(flag) {
  case 1: 
    log.info("didispace.com: 1"); 
    break;
  case 2:
    log.info("didispace.com: 2");
    break;
  case 3:
    log.info("didispace.com: 3");
    break;
  case 4:
    log.info("didispace.com: 4");
    break;
  default:
    log.info("didispace.com: x");
}
```

하지만 뭔가 아직도 아쉬움이 있어요. 그래서&#x20;

Java 14 의 Switch 의 개선된 기능을 한번 써봤어요.

```java
switch(flag) {
  case 1  -> log.info("didispace.com: 1");
  case 2  -> log.info("didispace.com: 2");
  case 3  -> log.info("didispace.com: 3");
  case 4  -> log.info("didispace.com: 4");
  default -> log.info("didispace.com: x");
}
```

코드량도 줄었고 보기도 훨씬 편해졌어요.

Java 14의 Switch 문구에 Lambda 문법를 적용할수가 있어요. 많은 case 로 분할하는 방식이 간소화 되었네요.

그리고 자꾸 깜빡하고 빼먹는 break도 쓸필요가 없게 되었어요.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blakes-organization.gitbook.io/rainsister/java/java14.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
