Scalac 解析 Java 代码时永久隐藏警告 - 编译器错误?

发布于 2024-11-11 04:08:07 字数 604 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

多像笑话 2024-11-18 04:08:07

除了使用 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.

鸠魁 2024-11-18 04:08:07

您有两个 Entity 引用,一个用于您的接口,另一个用于 javax.persistence.Entity

尝试用完整限定名称替换第二个,删除导入:

package iMP2020.domain;

public interface Entity {
    public Serializable getId();
}

package iMP2020.domain;

@javax.persistence.Entity
public class Asset {

You have two Entity references, one for your interface, and another one for javax.persistence.Entity.

Try to replace the second one with the full qualified name, removing the import:

package iMP2020.domain;

public interface Entity {
    public Serializable getId();
}

and

package iMP2020.domain;

@javax.persistence.Entity
public class Asset {
魔法唧唧 2024-11-18 04:08:07

我不认为这是一个错误。
导入与包成员同名是没有意义的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文