【问题标题】:IntelliJ IDEA 'class' or 'interface' expected预期 IntelliJ IDEA“类”或“接口”
【发布时间】:2018-04-04 13:09:25
【问题描述】:
public class StudentApp {
    public static void main(String[] args) {
        Student student1 = new Student("test");
        Student student2 = new Student("test","test");
        System.out.println(student2.getId());
    }
}

构造函数如下所示:

public Student(String firstName, String lastName){
        this.id=nextId++;
        this.name = firstName+" "+lastName;
    }

student2 的第一个参数是“预期的‘类’或‘接口’”,但它编译并运行得很好。这里可能有什么错误?

【问题讨论】:

  • 看起来像this
  • 重启 IDE 有帮助吗?
  • 没有,但我想通了,看看我的回答。谢谢

标签: java class intellij-idea interface


【解决方案1】:

转到语言注入页面:编辑器 |语言注入并取消选中或删除IDE创建的注入。

【讨论】:

  • 我觉得你应该先尝试“使缓存无效/重新启动”,通过文件菜单访问
【解决方案2】:

此错误主要是由于代码中存在额外的括号造成的。从代码中删除多余的括号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-09
    • 2014-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多