gpt4 book ai didi

java - Eclipse Java 编辑器中出现错误 "The method * is not applicable for the arguments",但问题 View 中没有出现错误

转载 作者:行者123 更新时间:2023-12-01 10:09:39 25 4
gpt4 key购买 nike

我有一个名为 ParentClass 的类(class)和两个子类,我们称它们为 Child1Child2ParentClass 延伸.

我有一个方法可以收到 ParentClass作为参数,如下所示:

private void myMethod(ParentClass myObject) {
// Do something...
}

我应该能够调用该方法并传递两个子类中任何一个的实例(因为它们从 ParentClass 扩展),如下所示

Child1 child1 = new Child1();
Child2 child2 = new Child2();

myMethod(child1); // Error is displayed on this line
myMethod(child2); // Error is displayed on this line

但是 Eclipse Java 编辑器提示这个错误:

The method myMethod(ParentClass) in the type Test is not applicable for the arguments (Child1)

奇怪的是,错误仅显示在Java编辑器中,但显示在Problems上或Markers查看,还没有上Project Explorer查看,代码符合并成功运行,所以我不确定为什么编辑器中显示错误。

------编辑------

尝试清理项目,使用 -clean 重新启动 Eclipse选项,在新工作区中导出和导入项目。

最佳答案

您可以删除问题 View 中的错误。完成此操作后,进行全新构建。如果问题不再出现,则您可能已经解决了它。您可能会尝试进行“验证”,但这通常适用于其他类型的问题。如果它是 Maven 项目,您也可以尝试 Run->Maven clean verify。这将“从命令行”编译它,并确保 Eclipse 不会神奇地为您解决依赖关系。然而,基本上,我发现问题在修复后仍保留在问题窗口中。我很少在正常工作中使用 Windows 输出,通常只有在项目中某处出现我不理解的红色 X 时才使用。

关于java - Eclipse Java 编辑器中出现错误 "The method * is not applicable for the arguments",但问题 View 中没有出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36211204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com