What are the differences between asInstanceOf[T] and (o: T) in Scala?
foo.asInstanceOf[Bar] is a type cast, which is primarily a runtime operation. It says that the compiler should be coerced into believing that foo is a Bar. This may result in an error (a ClassCastException) if and when foo is evaluated to be something other than a Bar at runtime. foo:Bar is a type ascription, which … Read more