Scala-Java 不兼容引用与静态内部类同名的类中的静态字段
拿这个Java类来说:
public class Fisk {
public static class A {
}
public static A A = new A();
}
这个Java代码可以工作:
Fisk.A a = new Fisk.A();
Fisk.A b = Fisk.A;
但是从Scala调用它:
val fisk = new Fisk.A()
val strupp = Fisk.A
会导致编译器错误:
error: ambiguous reference to overloaded definition,
[INFO] both variable A in object Fisk of type Fisk.A
[INFO] and object A in object Fisk of type object Fisk.A
[INFO] match expected type ?
[INFO] val strupp = Fisk.A
[INFO] ^
[ERROR] one error found
任何人都知道解决这个问题的方法,还是我必须重命名我的静态字段?
-- 安德烈亚斯
Take this Java class:
public class Fisk {
public static class A {
}
public static A A = new A();
}
This Java code works:
Fisk.A a = new Fisk.A();
Fisk.A b = Fisk.A;
But calling it from Scala:
val fisk = new Fisk.A()
val strupp = Fisk.A
results in compiler-error:
error: ambiguous reference to overloaded definition,
[INFO] both variable A in object Fisk of type Fisk.A
[INFO] and object A in object Fisk of type object Fisk.A
[INFO] match expected type ?
[INFO] val strupp = Fisk.A
[INFO] ^
[ERROR] one error found
Anyone knows a way around this, or do I have to rename my static field?
--
Andreas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是解释和解决方案。
Here's an explanation together with a solution.