Use type of “Any” carefully in Scala
Think about the code below:
1 2 3 4 5 6 7 8 |
object My extends App { def increment(key: Any) { println(key); } increment("hello"); increment("world", 6, 7); } |
I intent to see the compiler error for second ‘increment’ int the first place. But it don’t, the compiler report ok and the output of the program is:
1 2 |
hello (world,6,7) |
The compiler recognize the three arguments “world”, “6”, “7” as a tuple of (“world”, 6,… Read more »