Skip to content

Instantly share code, notes, and snippets.

@arkadius
Created September 15, 2014 19:59
Show Gist options
  • Save arkadius/95795558f4cf287c41e3 to your computer and use it in GitHub Desktop.
Save arkadius/95795558f4cf287c41e3 to your computer and use it in GitHub Desktop.
trait CastingBox[T] {
val value: Any
def casted(implicit typeable: Typeable[T]): T = typeable.cast(value) match {
case Some(t) => t
case None => throw new ClassCastException(s"Cannot cast $value to expected type")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment