You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
objectTest {
varprev:Any= _
deftest[T](x: T):T= {
classA(valelem:T)
if (prev ==null) {
vala=newA(x)
prev = a
x
} else {
prev match {
caseprev: A=>// This should warn, but doesn't
prev.elem
case _ =>
x
}
}
}
defmain(args: Array[String]):Unit= {
test(1)
valx:String= test("") // ClassCastException: java.lang.Integer cannot be cast to java.lang.String
}
}
There's no way to distinguish instances of a local class coming from different method calls, so the type test is never safe and should always require an @unchecked annotation.