加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Scala包对象不会将伴随对象带入范围?

发布时间:2020-12-16 18:18:24 所属栏目:安全 来源:网络整理
导读:开发了一个如下所示的小包对象: 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
开发了一个如下所示的小包对象:

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是包engine.logic.sync下的顶级对象.

以下是我访问它的方式:

engine.logic.Sync.aMemberDef(var:String)

但是,编译器抛出错误对象Sync不是包engine.logic的成员.那么解决方法是什么?我如何弄乱我的包装?

谢谢!

解决方法

如果要创建实例别名,只需使用val:

val Sync = engine.logic.sync.Sync

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读