In Scala you can define parameters that descend from other one that take the first one as parameter. For example in Lift you can find such things in Record and Mapper
MongoMetaRecord[BaseRecord <: MongoRecord[BaseRecord]]
What does it mean and how is that useful ?
This is a pattern often used to let an abstract class know about the type of the actual concrete class that extends it. It is sometimes useful to know what that final concrete type is — for instance, to use it as the return type of a method that produces a copy of the current object.
Suppose you want to do this — let an abstract class
Abstractknow about the concrete type implementing it. You could start by defining a type parameter, maybe like this:But then you realize that actually,
Ashould be a subclass ofAbstractitself, as you don’t want subclasses to provide a random parametrization. So you could add this:… but you’ll soon realize that
Abstracthas turned into a generic type as well, so you’ll rather need this:As a final step, you’ll probably want to make
Acovariant if you can, so as to allow intermediate abstract classes along the inheritance path fromAbstractto the final concrete class:This means that every non-leaf (abstract) type should be parametrized, and that only the final concrete class will be able to drop the type parameter.