scala: defining a tratit and referencing the corresponding companion object
- by opensas
I'm trying to define a trait that uses the corresponding companion object, that is, the componion object of the class using the trait.
for example, I have:
:paste
class Parent {
def callMyCompanion = print(Parent.salute)
}
object Parent {
def salute = "Hello from Parent companion object"
}
class Child extends Parent {
}
object Child {
def salute = "Hello from Child companion object"
}
And then I create a parent object:
scala> val p = new Parent()
p: Parent = Parent@1ecf669
scala> p.callMyCompanion
Hello from Parent companion object
But with a child:
scala> val c = new Child()
c: Child = Child@4fd986
scala> c.callMyCompanion
Hello from Parent companion object
I'd like to get: Hello from Child companion object
How can I achieve it???