1
回答
scala中一个很奇怪的问题
注册华为云得mate10,2.9折抢先购!>>>   

abstract class Element {
  def contents: Array[String]
  val height = contents.length
  val width = if(height ==0 ) 0 else contents(0).length

  override def toString = contents(0)
}
class ArrayElement(override val contents: Array[String]) extends Element

class LineElementF(s: String) extends Element {
  override val contents = Array(s)
}
class LineElementT(s: String) extends Element {
  override def contents = Array(s)
}



定义的时候没问题,但在创建LineElementT的时候
val lef = new LineElementF("Wrong")

提示空指针异常

举报
pseudo
发帖于2年前 1回/116阅
顶部