rspec/rules/S2133/java/rule.adoc

38 lines
654 B
Plaintext

== 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' ``++.class++`` property.
=== Noncompliant code example
[source,java]
----
MyObject myOb = new MyObject(); // Noncompliant
Class c = myOb.getClass();
----
=== Compliant solution
[source,java]
----
Class c = MyObject.class;
----
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[]