Hi I come across this piece of code, but could not understand this. The confusing place is "V <: Vector[V]", this means V is a subtype of Vector[V] ? very confusing here.
trait Vector[V <: Vector[V]] { this: V =>
def +(other: V): V
}
Hi I come across this piece of code, but could not understand this. The confusing place is "V <: Vector[V]", this means V is a subtype of Vector[V] ? very confusing here.
trait Vector[V <: Vector[V]] { this: V =>
def +(other: V): V
}
It's called F-bounded type polymorphism and
is usually attempted when someone is trying to solve a common problem of abstraction in object-oriented languages: how to define a polymorphic function that, though defined in terms of a supertype, will when passed a value of some subtype will always return a value of the same subtype as its argument.
(from a recent blog post "F-Bounded Type Polymorphism Considered Tricky" by Kris Nuttycombe)
Also see this SO question: What does "Recursive type bound" in Generics mean?