Inspectopedia Help

Unnecessary unboxing

Reports unboxing, that is explicit unwrapping of wrapped primitive values.

Unboxing is unnecessary as of Java 5 and later, and can safely be removed.

Examples:

  • Integer i = Integer.valueOf(42).intValue();Integer i = Integer.valueOf(42);

  • int k = Integer.valueOf(42).intValue();int k = Integer.valueOf(42);

    (reports only when the Only report truly superfluously unboxed expressions option is not checked)

Use the Only report truly superfluously unboxed expressions option to only report truly superfluous unboxing, where an unboxed value is immediately boxed either implicitly or explicitly. In this case, the entire unboxing-boxing step can be removed. The inspection doesn't report simple explicit unboxing.

This inspection only reports if the language level of the project or module is 5 or higher.

Inspection options

Here you can find the description of settings available for the Unnecessary unboxing inspection, and the reference of their default values.

Only report truly superfluously unboxed expressions

Not selected

Inspection Details

Available in:

IntelliJ IDEA 2024.2, Qodana for JVM 2024.2,

Plugin:

Java, 242.SNAPSHOT

Last modified: 20 February 2024