I am writing a class that serves as a base class for a series of singleton objects. In every single object there will be vals representing certain properties, and I want to write a method that for each single object only accepts the objects it creates.
So, I have the following:
class Obj[M <: Maker] class Maker { implicit val me: this.type = this def make[M <: Maker](implicit maker: M) = new Obj[M] def accept(obj: Obj[this.type]) = {...} }
So far so good. Then I want to declare one of these singleton objects:
object M extends Maker { val a = make }
But then if I try this:
M.accept(Ma)
then I get a compile time error:
type mismatch; found : com.test.Obj[object com.test.M] required: com.test.Obj[com.test.M.type]
My questions:
- What type of
object com.test.M and how is it different from com.test.M.type ? - How can I do this in a smarter way?
object types scala singleton
Jean-philippe pellet
source share