Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on In Java 3 = 12. Parent comment
String splat = 1 + 2 + " = " + 1 + 2; System.out.println(splat);
The JLS spec [0] accounts for this in its treatment of the '+' operator:
"If the type of either operand of a + operator is String, then the operation is string concatenation."
This does seem like idiosyncratic behaviour for java to be honest.
I don't think it's the compiler doing it either, because this will throw a null-pointer exception:
Integer borken = null; String splat = borken + 2 + " = " + 1 + 2; System.out.println(splat);
Plus.java:8: error: bad operand types for binary operator '+' String splat = borken + 2 + " = " + 1 + 2;
There are no comments on this comment yet.
The JLS spec [0] accounts for this in its treatment of the '+' operator:
"If the type of either operand of a + operator is String, then the operation is string concatenation."
This does seem like idiosyncratic behaviour for java to be honest.
I don't think it's the compiler doing it either, because this will throw a null-pointer exception:
EDIT: Also interesting, if I drop the language level to 1.4 I get this error: [0] https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.htm...