Class PatternExpr

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

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
See Also: