James Gough

Distinguished Engineer, Java Champion, Speaker and Author
JDConf Day 2: Notes and Thoughts

28 Oct 2020

A Few New Cool Features in Modern Java @venkat_s

Venkat is faded-up and we are ready to go, expecting to not catch half of this!

Smart Casting/Pattern Matching
if (input instanceof String str) {
    var length = str.length();
Switch Expressions

Lots of fixes and new ideas here to avoid potential bugs when working with Switch expressions.

public static String process(int input) {
    return switch(input) {
        case 1 -> "one";
        case 2,3 -> "two or three"
        case 4 -> {
            //some code
        default -> "whatever";
Text Blocks

It has taken many years to get this and a lot of bad code along the way!

    String message = """
    First Line
    Second Line

Venkat also covered Records and Sealed classes, but my fingers and brain were hurting :).

Modern Java with IntelliJ IDEA @trisha_gee

75% of developers are using Java 8 according to the latest JetBrains survey. Two main options for moving to modern Java is to move to Java 11 for LTS support. The other option is to move to Java 15 and the current release, however you need to ensure that you are ready to upgrade every 6 months.

IntelliJ IDEA can help you with providing support to download JDKs and versions from different vendors. IJ will also help you detect which versions of the JDK that you have installed. Java 11 introduces var and IJ will allow you to use alt+enter to replace with var. IJ will give you inlay hints to give you type information if the naming of the method or variable is not clear.

IJ will replace immutable collections with the .of on collections. Top tip: Highlight a block of code, alt+enter will give you options for formatting that block of code. Java 11 will allow you to collect to an unmodifiable list. IJ refactoring are always safe, and will never break the behavior.

Switch expressions refactoring are available in IJ and helps to refactor switch statements to something that is far more readable. Records seem to be one of the favorite features of most of the speakers.

Enabling Java: Windows on Arm64 – A Success Story! @mon_beck

Please see this post