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

scala:创建对象时的循环引用?

发布时间:2020-12-16 08:53:07 所属栏目:安全 来源:网络整理
导读:我不小心遇到了这种情况(简化示例以解决问题): abstract class Element(val other: Element)case object First extends Element(Second)case object Second extends Element(First)object Main { def main(arguments: Array[String]) { val e1 = First val
我不小心遇到了这种情况(简化示例以解决问题):

abstract class Element(val other: Element)

case object First extends Element(Second)
case object Second extends Element(First)

object Main {
  def main(arguments: Array[String]) {
    val e1 = First
    val e2 = Second
    println("e1: "+e1+"   e1.other: "+e1.other)
    println("e2: "+e2+"   e2.other: "+e2.other)
  }
}

有人想猜测输出吗?

(编辑:李大同)

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

    推荐文章
      热点阅读