What are the differences between asInstanceOf[T] and (o: T) in Scala?

Viewed 26100

I saw that there are two methods to cast an object in Scala:

foo.asInstanceOf[Bar]
(foo: Bar)

When I tried, I found that asInstanceOf doesn't use implicit conversion whereas the other one does.

What are the differences of behavior between these two methods? And where is it recommended to use one over the other?

4 Answers
Related