rspec/rules/S3016/java/rule.adoc

49 lines
953 B
Plaintext
Raw Normal View History

== Why is this an issue?
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.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public class MyClass {
short s = 0; // Noncompliant
public short doubleSmallNumber(short num) { // Noncompliant
return num+num;
}
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public class MyClass {
int s = 0;
public int doubleSmallNumber(int num) {
return num+num;
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]