rspec/rules/S1118/java/rule.adoc
2023-10-18 08:16:10 +00:00

58 lines
1010 B
Plaintext

== Why is this an issue?
include::../description.adoc[]
=== Exceptions
When a class contains `public static void main(String[] args)` method it is not considered as a utility class and will be ignored by this rule.
include::../howtofix.adoc[]
=== Code examples
==== Noncompliant code example
[source,java,diff-id=1,diff-type=noncompliant]
----
class StringUtils { // Noncompliant
public static String concatenate(String s1, String s2) {
return s1 + s2;
}
}
----
==== Compliant solution
[source,java,diff-id=1,diff-type=compliant]
----
class StringUtils { // Compliant
private StringUtils() {
throw new IllegalStateException("Utility class");
}
public static String concatenate(String s1, String s2) {
return s1 + s2;
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Hide this public constructor.
Add a private constructor to hide the implicit public one.
'''
endif::env-github,rspecator-view[]