Description
http://io.livecode.ch/learn/namin/unsound/scala
object App {
trait A { type L >: Any}
def upcast(a: A, x: Any): a.L = x
lazy val p: A { type L <: Nothing } = p
def coerce(x: Any): Int = upcast(p, x)
def main(args: Array[String]): Unit = {
println(coerce("Uh oh!"))
}
}
lazy
above is not necessary
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:101)
at App$.coerce(HelloWorld.scala:5)
at App$.main(HelloWorld.scala:8)
at App.main(HelloWorld.scala)