Skip to content

Use == instead of instanceof for primitive array type checks #35962

@sbrannen

Description

@sbrannen

Overview

For performance reasons, JDK libraries often use == instead of instanceof for primitive array type checks — for example, if (obj.getClass() == char[].class) instead of if (obj instanceof char[]).

The rationale is that there are no type hierarchies for primitive array types. Consequently using instanceof is unnecessary.

We should therefore migrate from instanceof to == where feasible.

Candidates

  • SynthesizedMergedAnnotationInvocationHandler.cloneArray(Object)
  • ObjectUtils.arrayEquals(Object, Object)

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions