Monday, 15 September 2014

Use asInstanceOf[T] carefully!

Background


Scala has nice static type checking engine but from time to time there are situations when we must downcast some general object. If this casting is not possible we expect that virtual machine will throw ClassCastExeption as fast as possible. Although it is not always true. Consider code below.