<div dir="ltr"><div>Hello, David,<br><br>Thank you for your reply.<br><br>What troubles beginners is that types which intuitively could be operated with the + operator require the use of the add() method,<br>while the String, treated as an object, can be concatenated with the + operator.<br>This inconsistency in logic somewhat creates noise in the learning process.<br>(Of course, it will seem natural after understanding more, but at the beginning of learning, it's all about confusion.)<br>However, I understand that everything cannot be changed (given Java's position as a leading language).<br><br>So, I'll reiterate that phrase: "Don't ask, just write, let it become a part of you!"</div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><br>/* GET BETTER EVERY DAY */<br><br><br></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">David Alayachew <<a href="mailto:davidalayachew@gmail.com">davidalayachew@gmail.com</a>> 於 2024年4月17日 週三 上午6:07寫道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">You missed a point.<div dir="auto"><br></div><div dir="auto">String is the single most used class in Java BY FAR. Nothing comes close to it. And the Java designers knew this would happen before hand.</div><div dir="auto"><br></div><div dir="auto">When you are the literal most used class in Java, you get a few privileges. Using + for concatenation is only one of them.</div><div dir="auto"><br></div><div dir="auto">String is informally known as a "Blessed Type". This is an informal name to represent types that are so frequently used or so useful that they get treated differently by the JVM.</div><div dir="auto"><br></div><div dir="auto">So, in short, blessed types get some extra love and some extra privileges. Since String is a "Blessed Type", it gets many privileges, one of which is the + operator.</div><br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Tue, Apr 16, 2024, 12:43 PM tzengshinfu <<a href="mailto:tzengshinfu@gmail.com" target="_blank">tzengshinfu@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi, folks,<br><br>I'm glad that "JEP 463: Implicitly Declared Classes and Instance main Methods" can help beginners start writing basic programs with limited skills and understanding. However, recently I came across this post [<a href="https://twitter.com/relizarov/status/1767978534314627304" rel="noreferrer" target="_blank">https://twitter.com/relizarov/status/1767978534314627304</a>] and I recall having asked similar questions here before [<a href="https://mail.openjdk.org/pipermail/amber-dev/2023-October/008334.html" rel="noreferrer" target="_blank">https://mail.openjdk.org/pipermail/amber-dev/2023-October/008334.html</a>]. But today, I am explaining Java's design to a beginner from the perspective of a semi-experienced developer.<br><br>As we transitioned our tech stack from C# to the Java ecosystem, we also welcomed a new colleague who was previously accustomed to PHP. During my guidance on Java, we had the following conversation:<br><br>New colleague: Why do we use `equals()` for string comparison instead of `==` or `===`?<br>Me: Because `String` is an object.<br>New colleague: Then why can we concatenate strings with the `+` operator?<br>Me: The `+` operator is actually shorthand for `StringBuilder.append()`. From an OOP perspective, you can also use `string1.concat(string2)`.<br>New colleague: Why isn't the `+` operator used for `BigDecimal` addition here?<br>Me: Because it's also an object...<br>New colleague: Looking back, if strings are objects, shouldn't it be `String string1 = new String()` and then `string1.setValue(new char[] { 's', 't', 'r', 'i', 'n', 'g' })`?<br>Me: That would be too cumbersome... By the way, how did you compare strings in PHP?<br>New colleague: `===`, `strcmp()` is also an option, but less common.<br>And after many more questions...<br>Me: Don't ask, just write, let it become a part of you!<br><br>Do you have any better explanations for Java's design for beginners?<div><br clear="all"><div><div dir="ltr" class="gmail_signature"><br>/* GET BETTER EVERY DAY */<br><br><br></div></div></div></div>
</blockquote></div></div>
</blockquote></div>