开发了一个小包装对象,如下所示:
package object logic {
type Chat = engine.logic.chat.Chat
type History = engine.logic.history.History
type Meta = engine.logic.meta.Meta
type Notification = engine.logic.notification.Notification
type Service = engine.logic.service.Service
type State = engine.logic.state.State
type Sync = engine.logic.sync.Sync
}
看起来我误解了包对象的重点,因为我认为前面会将伴随对象Sync
带入范围。
Sync
是package engine.logic.sync
下的顶级对象。
以下是我访问它的方式:
engine.logic.Sync.aMemberDef(var: String)
但编译器会抛出错误object Sync is not a member of package engine.logic
。那么解决方法是什么?我如何弄乱我的包装?
谢谢!
答案 0 :(得分:6)
如果要创建实例别名,只需使用val:
val Sync = engine.logic.sync.Sync