rspec/rules/S3027/java/rule.adoc

46 lines
824 B
Plaintext

== Why is this an issue?
An ``++indexOf++`` or ``++lastIndexOf++`` call with a single letter ``++String++`` can be made more performant by switching to a call with a ``++char++`` argument.
=== Noncompliant code example
[source,java]
----
String myStr = "Hello World";
// ...
int pos = myStr.indexOf("W"); // Noncompliant
// ...
int otherPos = myStr.lastIndexOf("r"); // Noncompliant
// ...
----
=== Compliant solution
[source,java]
----
String myStr = "Hello World";
// ...
int pos = myStr.indexOf('W');
// ...
int otherPos = myStr.lastIndexOf('r');
// ...
----
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[]