9. Adding comments in text blocks
Question: Can we add comments in text blocks?
Official answer (according to the Java Language Specification): The lexical grammar implies that comments do not occur within character literals, string literals, or text blocks.
You might be tempted to try something like this, thinking it’s a quick hack, but I really don’t recommend it:
String txt = """
foo /* some comment */
buzz //another comment
""".replace("some_regex","");
Short answer: No, we cannot have comments in text blocks.
Let’s move on and talk about mixing ordinary string literals with text blocks.