rspec/rules/S3016/java/rule.adoc

30 lines
645 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
public class MyClass {
short s = 0; // Noncompliant
public short doubleSmallNumber(short num) { // Noncompliant
return num+num;
}
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
public class MyClass {
int s = 0;
public int doubleSmallNumber(int num) {
return num+num;
}
}
----