I'm kinda new to scala. I got into trouble while trying to return object type.
Here is the code.
It shows "error: not found: type A"
object A{}
object B {
def getInstance() : A = {
return A
}
}
If I do similar kind of thing with class instance, it wont show any problem.
class A{}
object B {
def getInstance() : A = {
return new A
}
}
As far as I know object type is a singleton instance of class. What am I missing here?
Compiler complains that can not find type A because in your case A is a name of an object not a type, use A.type to refer to type, like this:
object A
object B {
def getInstance: A.type = A
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With