0

What happens when executing

String s = "str" + 2;

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

Paolo
  • 2,407
  • 5
  • 30
  • 43

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
  • 32,670
  • 6
  • 50
  • 72