Inspectopedia Help

Number constructor call with primitive argument

Reports instantiations of new Long, Integer, Short, or Byte objects that have a primitive long, integer, short, or byte argument.

It is recommended that you use the static method valueOf() introduced in Java 5. By default, this method caches objects for values between -128 and 127 inclusive.


Integer i = new Integer(1); Long l = new Long(1L);

After the quick-fix is applied, the code changes to:

Integer i = Integer.valueOf(1); Long l = Long.valueOf(1L);

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

Use the Ignore new number expressions with a String argument option to ignore calls to number constructors with a String argument.

Use the Report only when constructor is @Deprecated option to only report calls to deprecated constructors. Long, Integer, Short and Byte constructors are deprecated since JDK 9.

Inspection options




Ignore new number expressions with a String argument



Report only when constructor is @Deprecated



Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3


Java, 233.SNAPSHOT

Last modified: 13 July 2023