-
Bug
-
Resolution: Fixed
-
P4
-
8
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."
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."