47 lines
919 B
Plaintext
47 lines
919 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's `.class` property.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
MyObject myOb = new MyObject(); // Noncompliant
|
|
Class c = myOb.getClass();
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java,diff-id=1,diff-type=compliant]
|
|
----
|
|
Class c = MyObject.class;
|
|
----
|
|
|
|
|
|
|
|
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[]
|