たとえば、私はこのコードを持っています:
abstract class A {
def functionA() {
val a : A = null; // take null just for temporary, because I cannot think what should to put here
a.functionB
}
def functionB() {
print("hello")
}
}
class C extends A{
}
object Main extends App {
val c : C = new C()
c.functionB // print hello
c.functionA // ERROR
}
でfunctionA
、次の場合にオブジェクトを宣言したい: 現在のクラスが C の場合、a は型 C を持ちます。現在のクラスが D の場合、a は型 D を持ちます。できないため:
val a : A = new A // because A is abstract
Java ではこれを簡単に実行できますが、Scala ではそのようなことはできません。これを助けてください。
ありがとう :)