Be-Developer

JAVA 16 release

JAVA 16

  • 2021/03
  • preview 제외

    기능

    default method를 proxy로 호출가능

    Object proxy = Proxy.newProxyInstance(getSystemClassLoader(), new Class<?>[] { HelloWorld.class },
      (prox, method, args) -> {
          if (method.isDefault()) {
              return InvocationHandler.invokeDefault(prox, method, args);
          }
          // ...
      }
    );
    Method method = proxy.getClass().getMethod("hello");
    assertThat(method.invoke(proxy)).isEqualTo("world");
    

    day period

  • 하루중 언제인지 나타내는 포맷이 생김
    LocalTime date = LocalTime.parse("15:25:08.690791");
    System.out.println(date.format(DateTimeFormatter.ofPattern("h B")));
    // 3 오후
    // 3 in the afternoon
    

    Stream.toList method

    // ASIS
    ...stream().collect(Collectors.toList())
    // TOBE
    ...stream().toList();
    

records new addition

  • inner class 의 멤버로 record를 사용할 수 있게 되었다.
    class OuterClass {
      class InnerClass {
          Book book = new Book("Title", "author", "isbn");
      }
    }
    

pattern matching for instanceof

// ASIS
if (obj instanceof String) {
    String t = (String) obj;
}
// TOBE
if (obj instanceof String t) {
}

Incubator

vector api