Java string literal automatically interpreted as String object, but how?

后端 未结 3 1932
余生分开走
余生分开走 2021-01-12 00:42

What are the mechanics behind Java automatically interpreting string literals as String objects, since there are no overloaded operators and there is no default support for

3条回答
  •  不思量自难忘°
    2021-01-12 01:05

    Java actually does have a few overloaded operators. For example, + can be applied to String objects as well as to int, float, and other numerical types. In each case, the return type is defined by the type of the expression on each side of the +. However, all overloaded operators are predefined in the language; programmers have no mechanism in the language to define any others. See the language specification for details.

提交回复
热议问题