[B >: A]
means that sorted
can be called with any ordering on B, where B is a supertype of A.
I suppose A is the type parameter of the trait itself, i.e.
SeqLike is defined as SeqLike[A, This]
. To be exhaustive, as SeqLike[A, +This <: SeqLike[A, This] with Seq[A]]
. The This <: SeqLike[A, This]
is F-bounded polymorphism.
trait A[T <: A[T]] {} // the type parameter to A must be an A
class C extends A[C] {} // this is how you use it.
The actual return type of SeqLike.sorted
is This
.
This is useful, because this allows SeqLike's methods to not only return SeqLike
s, but also subtypes!
Going back to the simple exemple earlier...
trait Model[T <: Model[T]] {
def find(id: Int): T = ...
}
class User extends Model[User]
val model: User = new User().find(3) # no need to cast.