Explicit Type Conversion in Scala

I figured this out myself. There are two solutions:

1) Do the explicit cast:

var bar:Dog = foo.asInstanceOf[Dog]

2) Use pattern matching to cast it for you, this also catches errors:

var bar:Dog = foo match {
  case x:Dog => x
  case _ => {
    // Error handling code here
  }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)