bwroga
bwroga

Reputation: 5459

Converting Companion Object with Implicit

I want to "add" a field to a companion object without changing the companion object itself, using an implicit. In the following example, I want to be able to access the property "name" from object A. Is this possible?

implicit def a2b(???): ??? = B

object A
class A

object B {
    val name = "Bob"
}

Upvotes: 1

Views: 377

Answers (1)

Dylan
Dylan

Reputation: 13922

Try this:

implicit def a2b(aObj: A.type): B.type = B

Upvotes: 3

Related Questions