3
爲什麼scala會抱怨下面的代碼?具有相同變量名的Scala類繼承
scala> class Http(var status: Int)
defined class Http
scala> case class Post(url: String, data: String, status: Int) extends Http(status)
<console>:8: error: overriding variable status in class Http of type Int;
value status needs `override' modifier
case class Post(url: String, data: String, status: Int) extends Http(status)
^
scala> case class Post(url: String, data: String, sta: Int) extends Http(sta)
defined class Post
但這運行良好。
scala> class C(boo:Int)
defined class C
scala> case class D(far:Int, boo:Int) extends C(boo)
defined class D