How does the String class override the + operator?

前端 未结 7 1996
刺人心
刺人心 2020-11-22 12:25

Why in Java you\'re able to add Strings with the + operator, when String is a class? In theString.java code I did not find any implementation for this operator

相关标签:
7条回答
  • 2020-11-22 12:53

    First of all (+) is overloaded not overridden

    The Java language provides special support for the string concatenation operator (+), which has been overloaded for Java Strings objects.

    1. If left hand side operand is String it works as concatenation.

    2. If left hand side operand is Integer it works as addition operator

    0 讨论(0)
提交回复
热议问题