Wrapper type may be primitive
Reports local variables of wrapper type that are mostly used as primitive types.
In some cases, boxing can be source of significant performance penalty, especially in loops.
Heuristics are applied to estimate the number of boxing operations. For example, conversions inside loops are considered as much more numerous.
Example:
public void example() {
Integer value = 12;
needBox(value);
for (int i = 0; i < 10; i++) {
// Loop usages considered as happening more often
needPrimitive(value);
}
}
void needPrimitive(int value) {}
void needBox(Integer value) {}
After the quick-fix is applied:
public void example() {
int value = 12;
needBox(value);
for (int i = 0; i < 10; i++) {
// Loop usages considered as happening more often
needPrimitive(value);
}
}
void needPrimitive(int value) {}
void needBox(Integer value) {}
New in 2018.2
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023