Java 21 So How Should We Construct Strings Now?
<p>Java 21 brings in a lot of cool features, and one of them is the String Templates. While it serves more purposes than just classic String interpolation, for us Java developers, it’s yet another way to concatenate Strings in a “proper” way.</p>
<p>What is <em>proper,</em> though? I poked around the bytecode and learned some interesting and surprising things about different String concatenation and interpolation techniques in modern Java.</p>
<p>I’ve also compared it with the Kotlin way (under the hood) </p>
<p>But let’s begin with Java.</p>
<h2>operator</h2>
<p>We’ve always known that using a <code>+</code> operator is bad practice since Strings are immutable, and under the hood, a new String gets instantiated for every part we concatenate. However, as they say in Dutch, “meten is weten,” which means “measuring is knowing.” Let’s see what is <em>really</em> happening inside</p>
<p><a href="https://betterprogramming.pub/java-21-so-how-should-we-construct-strings-now-772752607d43">Website</a></p>