Which Java-specific annoyance fixed in Scala reduces surprises like the ones discussed in Java Puzzl
- by soc
Example: In Java this code falls through and prints "Mhhh..."
Integer i = new Integer(1);
Integer j = new Integer(1);
if (i == j) {
System.out.println("Equal");
} else if (i < j) {
System.out.println("Smaller");
} else if (i > j) {
System.out.println("Bigger");
} else {System.out.println("Mhhh...");}
In Scala the equivalent code does not even compile:
val a = new Integer(1)
val b = new Integer(1)
println { if(a == b) "Equal" else if(a < b) "Smaller" else if (a > b) "Bigger" else "Mhhh..."}