我得到"无法解决符号"在使用它的位置附近定义的类的错误。 我做了无效的缓存并多次重启InteliJ,但它没有帮助。 还有什么可能是错的?
class Vehicle(speed : Int){
val mph : Int = speed
def race() = println("Racing")
}
class Car(speed: Int) extends Vehicle(speed){
override val mph: Int=speed
override def race() = println("Racing Car")
}
class Bike(speed:Int) extends Vehicle(speed) {
override val mph:Int = speed
override def race() = println("Racing Bike")
}
object Test {
def main(args: Array[String]): Unit = {
println("Hello")
val x = Bike(4)
}
}
答案 0 :(得分:1)
编辑:这是有效的(区别在于您在测试对象上的Bike定义之前缺少new
关键字)
class Vehicle(speed : Int){
val mph : Int = speed
def race() = println("Racing")
}
class Car(speed: Int) extends Vehicle(speed){
override val mph: Int=speed
override def race() = println("Racing Car")
}
class Bike(speed:Int) extends Vehicle(speed) {
override val mph:Int = speed
override def race() = println("Racing Bike")
}
object Test {
def main(args: Array[String]): Unit = {
println("Hello")
val x = new Bike(4)
}
}
答案 1 :(得分:0)
您正在尝试创建没有关键字Bike
的{{1}}对象,并且没有具有相应new
功能的随播广告。似乎这让IDEA感到困惑。要直接创建类,您需要使用def apply
。