Skip to content

Recipe to remove excessive null check when instanceof is used #629

@greg-at-moderne

Description

@greg-at-moderne

What problem are you trying to solve?

Code conciseness.

x instanceof SomeType is guaranteed to give false when x is null.
Thus there's no need to check x != null additionally.

Describe the situation before applying the recipe

        if (x != null && x instanceof String) {
            System.out.println("String value: " + x);
        }

Describe the situation after applying the recipe

        if (x instanceof String) {
            System.out.println("String value: " + x);
        }

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions