String
is a special case in Java. It's a class, which I can examine in the source code, but it also has its own infix operator +
, which seems to be syntactic sugar for StringBuilder
.
For example,
"Hello " + yourName;
could become
new StringBuilder().append("Hello ").append(yourName).toString();
There are no user-defined operators in Java, so where is +
specified for String
?
Could the same mechanism be used to make additional operators, such as for vectors?