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

获取Scala中“超级”调用引用的符号

发布时间:2020-12-16 18:30:18 所属栏目:安全 来源:网络整理
导读:我正在为 refchecks阶段编写一个Scala编译器插件. 在给定呼叫站点的符号的情况下,如何访问“超级”呼叫所指的symbol? 例如,在 trait A { def m() {}}trait B extends A { def m() { super.m() }} 知道callsite super.m()的符号,我想得到特征A的符号. 解决方
我正在为 refchecks阶段编写一个Scala编译器插件.

在给定呼叫站点的符号的情况下,如何访问“超级”呼叫所指的symbol?

例如,在

trait A {
  def m() {}
}

trait B extends A {
  def m() { super.m() }
}

知道callsite super.m()的符号,我想得到特征A的符号.

解决方法

我认为使用自我类型注释和多重继承将为您服务:

trait HelperTrait {
  def helperMethod {println("calling helperMethod of HelperTrait")}
}

trait PublicInterface { this: HelperTrait =>
  def useHelperMethod 
  { 
    println("calling useHelperMethod of PublicInterface")
    helperMethod 
  }
}

class ImplementationClass extends PublicInterface with HelperTrait

var obj = new ImplementationClass()
obj.useHelperMethod
obj.helperMethod

(编辑:李大同)

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

    推荐文章
      热点阅读