I have been working with Scala for more than 4 years. Yet I am surprised at times to find elegant syntactic sugar like this:
scala> class C
defined class Cscala> class D extends C
defined class Dscala> 0 -> (new D:C)
res4: (Int, C) = (0,D@3c232051)scala> 0 -> ((new D).asInstanceOf[C]) // Old and boring
res5: (Int, C) = (0,D@1a531422)
This is another way of doing a typecast, a la Scala way!
scala> val x = 3 : Any
x: Any = 3
PS: verified on Scala 2.12!
To summarize a fabulous discussion on the golden rules of modern software development: