Having a problem with Scala import. I have an import problem with two classes. The first one:
package org.world
import org.gui.tokens.Token
object WorldObject {
}
abstract class WorldObject[A <: WorldObject[_]](var xPos: Float, var yPos: Float) {
def x = xPos
def y = yPos
def token: Token
^^^^^
def move(dx: Float, dy: Float) {// : A = new A(x + dx, y + dy)
xPos += dx // = x + dx
yPos += dy
}
}
and the second one:
package org.gui.tokens
object Token {
}
And the problem is that the return type of def token: Token is underlined in red with error saying
not found: type Token
All is fine with class locations. Other classes have no similar problems. I do not remember such a situation in Java, autoimport always worked perfectly. Here it only adds the import org.gui.tokens.Token statement repeatedly in the WorldObject file over and over again… why is that? What can I do about it?
Tokenis an object, so sayingdef token: Tokenmakes about as much sense to the compiler as sayingdef token: 5ordef token: "Hello".You either mean
def token = Token, if you want to return theTokenobject; or you meanclass Token {}; object Token extends Token {}in your tokens file, so there really is a class namedToken, or you meandef token: Token.type, which means that the method must return something of the type of the objectToken. (But there’s not much point, since the objectTokenis the only thing with the typeToken.type.)