Inspectopedia Help

Pattern variable can be used

Reports local variable declarations that can be replaced with pattern variables, which are usually more compact.

Example:

if (obj instanceof String) { String str = (String) obj; System.out.println(str); }

Can be replaced with:

if (obj instanceof String str) { System.out.println(str); }

This inspection only reports if the language level of the project or module is 16 or higher

New in 2020.1

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023