简体   繁体   中英

Access companion object from base trait

If I define a trait, I can access successor's fields. But what if one of those fields is in companion object (eg for speed, as static member), can I access it too?

Is there a relationship between TheTrait object and TheSuccessor object, as with TheTrait trait and TheSuccessor class?

As far as I can tell you cant. You could either let the companion object implement the trait, or maybe define an abstract method in the trait. Implementing classes could then provide access to the companion object by implementing the method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM