OlegMikheev.com

Java 23: It’s OK to Rethink and Reset

Last week, Java 23 was released, another short-term support version. The NY Java SIG hosted a meetup to celebrate and discuss the new and not so new features that it brings us.

[Correction] Project Loom and its virtual threads are fully available, and there is no lack of interesting things that make Java a modern language.

During the session, one tricky question in the field of string definitions was: How many spaces will the resulting text block string contain?

String s = """
    test
    """;

The correct answer is zero, but as a bonus it’s going to have a line terminator in the end. You may refer to the spec for more details.

On a less positive note on the String definitions front, was the removal of String Templates. They were introduced back in Java 21 as a preview feature, continued in Java 22, but suddenly got dropped from Java 23. Say buh-bye to goodies like:

String fullName = STR."{firstName} {lastName}".

The reasons behind the removal are discussed in-depth elsewhere, but to me the key take away is that preview features are exactly that – experiments, or proof of concepts that may or may not fly. It’s perfectly fine to take several iterations to reach a goal. It’s better to step back and rethink something rather than end up with a feature that compromises the reliability or security of the entire platform. Personally, I’m confident the virtual threads experiment is a success, but I’ll still use them cautiously in my work.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *