Scalac 解析 Java 代码时永久隐藏警告 - 编译器错误?
scalac Java 解析器对我的 Java 代码提出异议,
imported `Entity' is permanently hidden by definition of object Entity in package domain Asset.java
这似乎是导入与正在编译的包中具有相同名称的类之间的冲突。
在我的包中,我有一个
package iMP2020.domain;
public interface Entity {
public Serializable getId();
}
与来自不同包的导入类同名的
package iMP2020.domain;
import javax.persistence.Entity; // compiler warning
@Entity
public class Asset {
类,该包抱怨导入。 Javac 很高兴。请注意,我不必引用我的类版本 - 只要它的存在就足以触发导入警告。
我可以通过删除导入并显式引用 @Entity 来解决此问题,但这是否是编译器中的错误?
The scalac Java parser is taking objection to my Java code
imported `Entity' is permanently hidden by definition of object Entity in package domain Asset.java
This seems to be a collision between an import and a class with the same name in the package being compiled.
In my package I have a class
package iMP2020.domain;
public interface Entity {
public Serializable getId();
}
with the same name as an imported class from a different package
package iMP2020.domain;
import javax.persistence.Entity; // compiler warning
@Entity
public class Asset {
where it is complaining about the import. Javac is quite happy. Note that I don't have to reference my version of the class- just its existence is enough to trigger the warning on the import.
I can fix this by removing the import and explicitly referencing @Entity, but is it a bug in the compiler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了使用 Scala Eclipse 插件之外,我似乎无法重现此问题,因此我将等待其稳定后再得出结论。
I don't seem to be able to reproduce this except with the Scala Eclipse plugin, so I'm going to wait for that to stabilise before coming to a conclusion.
您有两个
Entity
引用,一个用于您的接口,另一个用于javax.persistence.Entity
。尝试用完整限定名称替换第二个,删除导入:
和
You have two
Entity
references, one for your interface, and another one forjavax.persistence.Entity
.Try to replace the second one with the full qualified name, removing the import:
and
我不认为这是一个错误。
导入与包成员同名是没有意义的。
I don't think it is a bug.
It doesn't make sense for an import to have the same name as a package member.