Class TypePatternExpr

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

public class TypePatternExpr extends PatternExpr implements NodeWithSimpleName<TypePatternExpr>, NodeWithFinalModifier<TypePatternExpr>

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