Java 18 Features Support
Java 18 has now been released, and starting from version 2022.1, IntelliJ IDEA offers support for it.
Support for code snippets
The @snippet tag for JavaDoc’s Standard Doclet was introduced in JDK 18 to simplify the inclusion of example source code in API documentation.
Even without an explicit wrapper, the snippet fragment is still recognized as Java code. Any language can be specified, and the language injection features will work for the snippets as well. For example, navigable references will work for all the elements available through imports:
It is not necessary to write all of the code in the snippet with the binding from the class. The fragment will be recognized similarly to JShell fragments by IntelliJ IDEA.
Patterns for switch expressions: the second preview
The specification for pattern matching for switch expressions, introduced in JDK17, has now been updated with the two basic changes that are already supported in IntelliJ IDEA:
- Any type of pattern (including guarded patterns) dominates constant cases. Dominance for pattern and non-constant cases is unchanged.
- For sealed hierarchies, subtypes are occasionally not possible for, or not castable to, the selector type. You no longer need to handle these subtypes to make the switch statements exhaustive.
Since Java 18, non-static inner classes (anonymous or not) don’t capture `this` if it’s not used, so the inspection Cleaner captures object reference has been updated accordingly. It will not trigger the following warning in code:
Additionally, in JDK18 the default charset is now UTF-8, instead of there being different default charsets depending on the platform. The Implicit platform default charset inspection, which reports the method and the constructor calls that implicitly use the platform’s default charset, has been updated accordingly.
Subscribe to Blog updates
Thanks, we've got you!
Java Annotated Monthly – December 2023
The December edition of Java Annotated Monthly is here! As usual, you’ll find all the latest Java and Kotlin updates as well as details of key industry events for networking and learning. This issue also features the latest release candidates and targeted JEPs alongside Java tutorials and articles a…
String Templates in Java – why should you care?
TLDR; The existing String concatenation options are difficult to work with and could be error prone. String Templates (a preview feature introduced in Java 21) greatly improves how we create strings in Java by merging constant strings with variable values. The name of this feature pretty much says …
Java Annotated Monthly – November 2023
Welcome to the Java Annotated Monthly – November 2023! As the Java world keeps on spinning, we've gathered a treasure trove of articles, talks, and insights to warm your Java developers’ hearts. This month's edition features a delightful blend of the latest technological advancements and the ever…
Java Annotated Monthly – October 2023
Welcome to the October edition of Java Annotated Monthly! In this issue, we're plunging into the world of Java and tech. We'll explore the latest and greatest in the recent release of Java 21, share exciting news about the new EAP for IntelliJ IDEA 2023.3, and bring you a handpicked selection of …