<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div class="markdown-here-wrapper" data-md-url="" style="" markdown-here-wrapper-content-modified="true">
<p style="margin: 0px 0px 1.2em !important;">On 14/03/2024 20:53,
Clement Cherlin wrote:</p>
<p style="margin: 0px 0px 1.2em !important;"></p>
<div class="markdown-here-exclude">
<p></p>
<blockquote type="cite" cite="mid:CALEU8=xVddJCMKnuqo4w=stSiarWuHaK9mSY9RPT+DLChBrRAQ@mail.gmail.com">
<pre>I'm going to assume you're joking here, so I don't feel the need to
write a thousand words about how terrible Java's casting syntax is.</pre>
</blockquote>
<p></p>
</div>
<p style="margin: 0px 0px 1.2em !important;"></p>
<p style="margin: 0px 0px 1.2em !important;">Honestly no, I wasn’t
joking, at least not from a semantic perspective. Let me see if
I can explain myself.</p>
<p style="margin: 0px 0px 1.2em !important;">Let’s say a string
interpolation literal is spelled like:</p>
<pre style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;font-size: 1em; line-height: 1.2em;margin: 1.2em 0px;"><code style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px; display: inline;white-space: pre; overflow: auto; border-radius: 3px; border: 1px solid rgb(204, 204, 204); padding: 0.5em 0.7em; display: block !important;">String"my name is \{name}"
</code></pre>
<p style="margin: 0px 0px 1.2em !important;">What is this
expression doing? Well, it’s taking some literal that looks like
a string, but has some embedded expression, and explicitly ask
to turn that thing into a String…</p>
<p style="margin: 0px 0px 1.2em !important;">Now, isn’t that what
(morally) a cast is for? E.g. the object you are casting has a
type (StringTemplate) and you want to turn it into something
else (String). Seems quite close. And, while cast between
reference types don't do much (beside changing the type), cast
between primitives, or between primitives and references (boxed
types) do end up changing the underlying representation. So
again, semantically we're not too far. Where I think cast is a
bad fit is that we can't use the cast syntax just as a syntactic
device. If cast syntax works, it means there's a casting
conversion between String and StringTemplate which means (as I
mentioned the other day) that pattern matching will need to come
along for the ride too.<br>
</p>
<p style="margin: 0px 0px 1.2em !important;">In terms of syntax, I
might agree with you that it’s not a great option, but the
“conversion vibe” that a cast gives isn’t totally off the mark.</p>
<p style="margin: 0px 0px 1.2em !important;">Maurizio</p>
<div title="MDH:PHA+PGJyPjwvcD48ZGl2IGNsYXNzPSJtb3otY2l0ZS1wcmVmaXgiPk9uIDE0LzAzLzIwMjQgMjA6
NTMsIENsZW1lbnQgQ2hlcmxpbiB3cm90ZTo8YnI+PC9kaXY+PGJsb2NrcXVvdGUgdHlwZT0iY2l0
ZSIgY2l0ZT0ibWlkOkNBTEVVOD14VmRkSkNNS251cW80dz1zdFNpYXJXdUhhSzltU1k5UlBUK0RM
Q2hCclJBUUBtYWlsLmdtYWlsLmNvbSI+PHByZT5JJ20gZ29pbmcgdG8gYXNzdW1lIHlvdSdyZSBq
b2tpbmcgaGVyZSwgc28gSSBkb24ndCBmZWVsIHRoZSBuZWVkIHRvCndyaXRlIGEgdGhvdXNhbmQg
d29yZHMgYWJvdXQgaG93IHRlcnJpYmxlIEphdmEncyBjYXN0aW5nIHN5bnRheCBpcy48L3ByZT48
L2Jsb2NrcXVvdGU+PHA+SG9uZXN0bHkgbm8sIEkgd2Fzbid0IGpva2luZywgYXQgbGVhc3Qgbm90
IGZyb20gYSBzZW1hbnRpYyBwZXJzcGVjdGl2ZS4gTGV0IG1lIHNlZSBpZiBJIGNhbiBleHBsYWlu
IG15c2VsZi48L3A+PHA+TGV0J3Mgc2F5IGEgc3RyaW5nIGludGVycG9sYXRpb24gbGl0ZXJhbCBp
cyBzcGVsbGVkIGxpa2U6PC9wPjxwPmBgYDxicj5TdHJpbmcibXkgbmFtZSBpcyBce25hbWV9Ijxi
cj5gYGA8L3A+PHA+V2hhdCBpcyB0aGlzIGV4cHJlc3Npb24gZG9pbmc/IFdlbGwsIGl0J3MgdGFr
aW5nIHNvbWUgbGl0Z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