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.
Example:
After the quick-fix is applied, the code changes to:
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
CachedNumberConstructorCall- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
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
Here you can find the description of settings available for the Number constructor call with primitive argument inspection, and the reference of their default values.
- Ignore new number expressions with a String argument
Default value:
Not selected- Report only when constructor is @Deprecated
Default value:
Selected
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |