Class PatternExpr

All Implemented Interfaces:
NodeWithRange<Node>, NodeWithSimpleName<PatternExpr>, NodeWithTokenRange<Node>, NodeWithType<PatternExpr,​ReferenceType>, Observable, Visitable, HasParentNode<Node>, Cloneable

public class PatternExpr extends Expression implements NodeWithSimpleName<PatternExpr>, NodeWithType<PatternExpr,​ReferenceType>

The instanceof statement

Java 1.0 to 13

Not available.

Java 14

Since JDK14, it is possible to bind a variable that is cast to the type being tested against. This is referred to as a Pattern within JEP305, and avoids the need to cast to the desired type.
Example:

 tool instanceof Drill d
                 ^^^^^^^
                 Pattern
 

Note: While this is exclusively used within instanceof operators for now, JEP305 suggests this might be used more widely in the future (e.g. in switch expressions/statements).

JDK14 Grammar

Per JEP305 (not currently listed within the JLS):
Pattern:
      ReferenceType Identifier
Author:
Roger Howell
See Also:
InstanceOfExpr, JEP305: https://bugs.openjdk.java.net/browse/JDK-8181287, https://docs.oracle.com/javase/specs/jls/se11/html/jls-15.html#jls-15.20