Relaxing constraint for text blocks to start on new line?
Tagir Valeev
amaembo at gmail.com
Wed Nov 30 12:19:22 UTC 2022
Hello!
I'm always confused with multi-line literals in Kotlin, like
val myXml = """<xml>
<hello>
<world>!!!</world>
</hello>
</xml>""".trimIndent()
Here, trimIndent does nothing, and the indentation still persists,
because of the first line. You can easily miss it, as it's not aligned
to the rest.
I think disallowing starting the literal on the first line in Java was
the right decision, assuming that most of the applications are
actually multi-line literals, not just the way to avoid escaping of ".
With best regards,
Tagir Valeev.
On Wed, Nov 30, 2022 at 12:11 PM Jim Laskey <james.laskey at oracle.com> wrote:
>
> Technically there is no reason why we couldn’t. It would, however, be difficult to call the result a text ‘block’. Thick quotes?
>
> The answer is simply ‘reserved for future use’. The rationale is to provide the block structure that you’ve come to know and leave a space where we could in future we could put additional information describing the content.
>
> Cheers,
>
> — Jim
>
>
>
> 📱
>
> On Nov 30, 2022, at 6:10 AM, Vikram Bakshi <vab2048 at gmail.com> wrote:
>
>
> Hi all,
>
> Does anybody on the mailing list want to bite and answer the message I had sent earlier?
>
> Even if it is to say "no we will not be doing that because <xyz>" - that would suffice!
>
> Regards,
> Vikram
>
>
> On Tue, Nov 22, 2022 at 10:42 AM Vikram Bakshi <vab2048 at gmail.com> wrote:
>>
>> Hello,
>>
>> Text blocks are a great feature of the Java language. On the JEP page one of the listed goals of text blocks is to:
>>
>> Enhance the readability of strings in Java programs that denote code written in non-Java languages.
>>
>>
>> Currently when attempting to use text blocks for short strings which can fit on one line for a non-Java language (e.g. JSON) we still need to start the string on another line.
>>
>> For example:
>>
>> ```java
>> var json = """
>> { "color": "red", "value": "#f00" } """
>> ```
>>
>> It would be a lot nicer to have the ability to use the triple quote to define strings like this on one line:
>>
>> ```java
>> var json = """{ "color": "red", "value": "#f00" } """
>> ```
>>
>> Currently that is not possible and using a normal quote for strings, ", requires us to escape all of the subsequent quotes on the same line - which is a real pain.
>>
>> Obviously we can just continue to start on the next line to avoid the issue - but is it possible to consider an extension to text blocks which allow for this use case (short one line strings)?
>>
>> Regards,
>> Vikram
More information about the amber-dev
mailing list