0

What happens when executing

String s = "str" + 2;

Is there a method of String class that correspond exactly to the + operator?

Paolo
  • 2,461
  • 5
  • 31
  • 45

1 Answers1

1

From Java Language Specification (emphasis mine):

If only one operand expression is of type String, then string conversion (§5.1.11) is performed on the other operand to produce a string at run time. The result of string concatenation is a reference to a String object that is the concatenation of the two operand strings.

Christian Tapia
  • 33,620
  • 7
  • 56
  • 73