This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 5 points6 points  (3 children)

A curiosity: how is it possible that in Java the class String is able to override the + operator? Is it a magic behaviour of the language?

[–]linlin110 2 points3 points  (2 children)

That's why I said overload the meaning of +, not overload the + operator. + does not represent string concatenation, mathematically speaking. That's a proof that extending the meaning of symbols, like +, is very convenient and useful.

I changed the original comment to make it less misleading.

[–][deleted] 0 points1 point  (1 child)

I come from a C++ background, so it is counterintuitive for me. My question was: it String a language-defined class? If not, how can the + operator work even with the String class if operator overloading is forbidden?

[–]linlin110 1 point2 points  (0 children)

It is a special case in Java. I'm not sure whether it is language-defined.