I'm using Scala and I want to extend a (singleton) object with a trait, which delivers a data structure and some methods, like this:
trait Tray[T] {
val tray = ListBuffer.empty[T]
def add[T] (t: T) = tray += t
def get[T]: List[T] = tray.toList
}
And then I'll would like to mix-in the trait into an object, like this:
object Test with Tray[Int]
But there are type mismatches in add
and get
:
Test.add(1)
// ...
How can I'll get this to work? Or what is my mistake?