斯卡拉 2.12.4 : Cannot access protected static Java method from another package anymore

标签 scala

我有一个带有 protected 静态方法的java类:

package parent;

public class Parent {

    protected static void parentMethod() {
        System.out.println("I'm in parent static method");
    }

}

在 Scala 2.12.4 (2.12.3) 之前,我可以像这样从另一个包调用这个方法:
package child

import parent.Parent

class Child extends Parent {

  def childMethod = {
    println("I'm in child method and calling parentMethod")
    Parent.parentMethod()
  }

}

但是 Scala 2.12.4 不会编译这段代码。我收到错误:

Error:(9, 12) method parentMethod in object Parent cannot be accessed in object parent.Parent Access to protected method parentMethod not permitted because prefix type parent.Parent.type does not conform to object Child in package child where the access takes place Parent.parentMethod()



这种访问模式对我来说非常重要,因为 JOOQ 代码生成使用了它。

发生了什么?

最佳答案

不错,这很可能是 this PR 引入的回归,作为 this issue 解决方案的一部分.

我已经开通了a ticket为此,您可以跟踪。同时,如果这种访问模式对您的应用程序至关重要,那么不幸的是,我认为您别无选择,只能暂时坚持使用 Scala 2.12.3。

编辑

该问题已为人所知,a fix has been already merged .截至撰写本文时,该补丁必将成为 2.12.5 版本的一部分。

关于斯卡拉 2.12.4 : Cannot access protected static Java method from another package anymore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48353393/

相关文章:

sql - SparkSQL 错误表未找到

scala - Playframework设置取决于环境

scala - Apache Flink:使用keyBy/connect维护流中的消息输入顺序

scala - 通过调用 toSet 丢失参数类型错误

scala - 当一个是返回值时如何推断类型?

Scala 2.10反射: constructor of case class inside a class

scala - 构造一个可重写的隐式

scala - 类型构造函数参数推断

Scala 代码分析器的目标是与外部匹配变量相同的案例变量名称 - "suspicous shadowing"

json - 将 Json 转换为 Map[String, String]