class X extends Map[String, String] {
def x(): X = { X() } // can't be compiled
}
can’t be compiled, the error is:
<console>:6: error: not found: value X
def x(): X = { X() } // can't be compiled
Why is X not found? I can’t see how to correct it.
UPDATE:
I know the reason now. What I want to do is create a class which extends HashMap, since Map() will return an instance of HashMap, so I thought I can just extends Map. Now, the correct code should be:
import scala.collection.immutable.HashMap
class X extends HashMap[String, String] {
def x(): X = { new X() }
}
Try
new X()instead ofX()— you’ll get another error, but it’ll set you on the right track I believe.In the latter case it is trying to invoke apply upon the expression denoted by
X(e.g. imagine whereXis defined asobject Xorval X) and not trying to invoke the constructor for class X.Happy coding.