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

4.2.2: Clarify that + doesn't convert char operand to decimal form

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8
    • specification

      JLS8 4.2.2 offers a summary of string concatenation as follows: "The string concatenation operator + (§15.18.1), which, when given a String operand and an integral operand, will convert the integral operand to a String representing its value in decimal form, and then produce a newly created String that is the concatenation of the two strings."

      Since char is an integral type, a sharp-eyed reader might think that "a"+'b' converts 'b' to its decimal form (resulting in the string "a98") when in fact 'b' is converted to the string "b" (resulting in the string "ab").

      A better summary is "The string concatenation operator + (§15.18.1), which, when given a String operand and an integral operand, will convert the integral operand to a String (representing the value in decimal form of a byte/short/int/long operand, or the character of a char operand), and then produce a newly created String that is the concatenation of the two strings."

            abuckley Alex Buckley
            abuckley Alex Buckley
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: