For a home assignment, I must define a polymorphic interface and its implementation.
The interface is below :
trait SortService[T] {
def sortData[T](l: List[T]): List[T]
def isSorted[T](l: List[T]): Boolean
}
So far, so good.
The problem occurred when I tried to write the implementation.
I though of something like
object SortServiceImplementation[T] extends SortService[T] {
def sortData[T](l: List[T]): List[T] = {
…
}
}
The specific part "object SortServiceImplementation[T] extends SortService[T] " is not accepted by the compiler.
object SortServiceImplementation extends SortService[Int] {
…
}
is ok but the functions inside SortServiceImplementation are, thus, not polymorphic.
Is there a syntactically correct way of implementing an interface with polymorphic functions or interfaces just can’t be implemented in a polymorphic way.