Changes in Java13

Both text blocks and switch expressions still are preview features!

Text Blocks

New way to use multiline strings. They start with 3 " and a newline.

String jsonBlock = """
{
  greeting: "Hello",
  audience: "World"
}
"""

Return value from switch expressions

Java12 introduced switch expressions. In Java13 the return keyword changes from break to yield.

boolean result = switch(boolValue) {
  case TRUE ->  {
    // do something  
    yield true;
  }
  case FALSE -> {
    // something else  
    yield false;
  }
  case FILE_NOT_FOUND -> {
    throw new UncheckedIOException("oh no!");
  }
}

Misc.

String API improvements

  • New String::stripIndent method. Removes indentation of text blocks.
  • String::translateEscapes translates escape sequences in Strings.

Reference(s)

https://blog.codefx.org/java/java-13-guide