rspec/rules/S5663/java/rule.adoc

41 lines
780 B
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
If a string fits on a single line, without concatenation and escaped newlines, you should probably continue to use a string literal.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
String question = """
What's the point, really?""";
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
String question = "What's the point, really?";
----
== Resources
2021-04-28 16:49:39 +02:00
* https://openjdk.java.net/jeps/378[JEP 378: Text Blocks]
* https://openjdk.org/projects/amber/guides/text-blocks-guide[Programmer's Guide To Text Blocks], by Jim Laskey and Stuart Marks
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Use simple literal for a single-line string.
endif::env-github,rspecator-view[]