Say I wanted to extend Scala’s MapLike trait with a concrete implementation, IntIntMap. In order to do so, I need to implement the following methods,
def get(key: A): Option[B]
def iterator: Iterator[(A, B)]
def + [B1 >: B](kv: (A, B1)): This
def -(key: A): This
What is the This type? Should my overriding method signature be,
override def +=(kv: (Int, Int)): IntIntMap = {
// logic
}
Or just scala.reflect.This? What about the class definition? Should it be,
class IntIntMap(...) extends MapLike[Int,Int,This] { ... }
or something else entirely?
You should extend
MapLike[Int, Int, IntIntMap], andThisbecomesIntIntMap.