rspec/rules/S2133/java/rule.adoc

47 lines
919 B
Plaintext
Raw Normal View History

== Why is this an issue?
Creating an object for the sole purpose of calling `getClass` on it is a waste of memory and cycles.
Instead, simply use the class's `.class` property.
2021-04-28 16:49:39 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
[source,java,diff-id=1,diff-type=noncompliant]
2021-04-28 16:49:39 +02:00
----
MyObject myOb = new MyObject(); // Noncompliant
Class c = myOb.getClass();
2021-04-28 16:49:39 +02:00
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
[source,java,diff-id=1,diff-type=compliant]
2021-04-28 16:49:39 +02:00
----
Class c = MyObject.class;
2021-04-28 16:49:39 +02:00
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this object instantiation and use "xxx.class" instead.
'''
== Comments And Links
(visible only on this page)
=== on 21 Nov 2024, 16:48:00 Alban Auzeill wrote:
[test-code-support-investigation-for-java] Decision for scope: Main -> All.
=== on 10 Oct 2014, 11:40:44 Freddy Mallet wrote:
Sounds good to me !
endif::env-github,rspecator-view[]