Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8351420

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

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 8, 11, 17, 21
    • 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).

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

              Created:
              Updated: