rspec/rules/S3016/java/rule.adoc
2021-04-28 18:08:03 +02:00

30 lines
645 B
Plaintext

The use of ``++short++``s saves a little bit of memory, but actually increases processor use because the JVM has no real capability for handling ``++short++``s. Instead, it must convert each ``++short++`` to an ``++int++`` before performing any operations on it, then convert it back to a ``++short++`` for storage.
== Noncompliant Code Example
----
public class MyClass {
short s = 0; // Noncompliant
public short doubleSmallNumber(short num) { // Noncompliant
return num+num;
}
}
----
== Compliant Solution
----
public class MyClass {
int s = 0;
public int doubleSmallNumber(int num) {
return num+num;
}
}
----