instanceof

The Java operator that checks whether a value is an instance of a type, and with a pattern also binds it to a typed variable.

In more detail

Older code wrote the check and then a separate cast. Pattern matching folds the two together, so value instanceof String text gives you text as a String inside the true branch.

Example

value instanceof String text

Related terms

Taught in

References

Certification courses