Discuss / Java / IDE 中使用 record 关键字报错

IDE 中使用 record 关键字报错

Topic source

庭除闲步

#1 Created at ... [Delete] [Delete and Lock User]

我在 idea 中使用 record 定义记录类时,提示错误,无法编译,我已经升级了 jdk 到 14 版本了

这是怎么回事呢

public record Point(int x, int y) {}

fredld22

#2 Created at ... [Delete] [Delete and Lock User]

同问:jdk15  record cannot be resolved to a type

廖雪峰

#3 Created at ... [Delete] [Delete and Lock User]

打开编译器开关--source 15 --enable-preview

设置了还是没有用  - -!

同问,我的是jdk15,并且已经打开了设置里的enable preview features for jdk15。

错误代码为:

public record Point(int x,int y) { }

错误信息是:

record 无法解析为类型

- 'record' is not a valid type name; it is a 

restricted identifier and not allowed as a type identifier 

in Java 15


  • 1

Reply