Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想使用隐式将字段“添加”到伴随对象而不更改伴随对象本身。在以下示例中,我希望能够从对象 A 访问属性“名称”。这可能吗?
implicit def a2b(???): ??? = B object A class A object B { val name = "Bob" }
尝试这个:
implicit def a2b(aObj: A.type): B.type = B