Given these Java class definitions:
class Base { int value; public <T extends Base> T self() { return (T) this; } } class Derived extends Base {}
this java code compiles fine:
new Derived().self();
but this Scala code does not run:
(new Derived).self();
Runtime Error:
java.lang.ClassCastException: Derived cannot be cast to scala.runtime.Nothing$
Why does this not work, and how to fix it?
source share