InteliJ无法解析它附近的名称

时间:2017-04-15 18:04:11

标签: scala intellij-idea name-resolution

我得到"无法解决符号"在使用它的位置附近定义的类的错误。 我做了无效的缓存并多次重启InteliJ,但它没有帮助。 还有什么可能是错的?

enter image description here

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)
  }
}

2 个答案:

答案 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)
  }
}

enter image description here

答案 1 :(得分:0)

您正在尝试创建没有关键字Bike的{​​{1}}对象,并且没有具有相应new功能的随播广告。似乎这让IDEA感到困惑。要直接创建类,您需要使用def apply