For example I have this code :
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
}
at functionA
, I want declare a object in case : if the current class is C, a will have type C. if the current class is D, a will have type D. Because I cannot do :
val a : A = new A // because A is abstract
In Java, I can do this easily, but I cannot do like that in Scala. Please help me this.
Thanks :)