In the code shown below, how can I convert EmptyTree to object (Singleton) ?
trait Tree[T] {
def contains(num: T): Boolean
def inc( num: T )
You have to fix the generic argument because that's the only time you can provide it:
scala> trait A[T]
defined trait A
scala> object B extends A[Int]
defined object B
Obviously you want to reuse EmptyTree for all types of T, so instead of defining A[SOMETYPE] for each type just use bottom type Nothing:
scala> object B extends A[Nothing]
defined object B
This object can be used with any tree.
That's exactly how Option[T] is implemented in Scala. Here is how None is defined:
case object None extends Option[Nothing]