は、私は少し二つのキューの例に混同しそうだ編。Scalaの特徴とScalaの第二でのプログラミングからスーパー例は
//class BasicIntQueue ...
override def get() = buf.remove()
override def put(x: Int) { buf += x }
私はオーバーライドして実装しましたし、期待される結果は同じです:
abstract class IntQueue {
def get(): Int
def put(x: Int)
}
import scala.collection.mutable.ArrayBuffer
class BasicIntQueue extends IntQueue {
private val buf = new ArrayBuffer[Int]
def get() = buf.remove()
def put(x: Int) { buf += x }
}
は、それはすべきではない:
ここではサンプルコードです。
質問2:形質に優れている理由
trait Doubling extends IntQueue {
abstract override def put(x: Int) { super.put(2 * x) }
}
class MyQueue extends BasicIntQueue with Doubling
私はsuperキーワードなしで試してみましたが、失敗しました。私はUML図を描いてきましたが、ファジィ推論のようなものがあります。
abstract override def put(x: Int) { super.put(2 * x) }
この倍増のラインは、BasicInQueueのメソッドをオーバーライドしますか?もしそうなら、なぜスーパーが必要でしょうか?なぜ私たちはできないのですか?
abstract override def put(x: Int) { 2 * x }
私の場合、上記の行は、新しい実装のBasicInQueueのメソッドをオーバーライドするだけでしょうか?抽象的なオーバーライドキーワードは、実行時にのみスタック操作のいくつかの並べ替えのためのものですか?とにかくスーパーが必要なのはなぜですか?スーパーは何を参照していますか?左のものは何ですか?したがって、BasicIntQueue with Doubling
では、BasicIntQueueを参照する倍音のスーパーキーワードですか?
ありがとうございます。