Remove the requirement to create a new String during concatenation with +

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • None
    • Affects Version/s: 8, 11, 17, 21
    • Component/s: specification
    • None

      JLS 15.18.1. "String Concatenation Operator +" unconditionally requires to create a new String object during concatenation with + (except for constant expressions).

      This seems excessive when one or both operands are empty strings.
      For example, given:
      var s = "abc"
      var t = ""
      the expression
      s + t == s
      evaluates to false because s + t cannot just evaluate to s.

      If nothing speaks against, concatenation with + should be allowed to return one of the operand if the other is empty.
      This already happens with String.concat(String).

            Assignee:
            Unassigned
            Reporter:
            Raffaello Giulietti
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: