# instanceof

An operator that tests whether an object is compatible with a given type.

## What does **instanceof** do in Java?

**instanceof** — An operator that tests whether an object is compatible with a given type.

```java
class LabelReader {
    int lengthOf(Object value) {
        if (value instanceof String text) {
            return text.length();
        }

        return 0;
    }
}
```

Level: Journeyman · [More Java terms at this level](https://www.ask-codey.com/glossary/subjects/java/journeyman)

Updated: September 27, 2026

Source: https://www.ask-codey.com/glossary/instanceof
