示例:
record Record(Integer x, String y) {
}
public static void test(List<Record> records) {
for (Record record : records) {
System.out.println(record.y());
Integer x = record.x;
System.out.println(x);
}
}
可以替换为:
record Record(Integer x, String y) {
}
public static void test(List<Record> records) {
for (Record(Integer x, String y) : records) {
System.out.println(y);
System.out.println(x);
}
}
仅当项目或模块的语言级别为 20 或更高时,此检查才会报告。
varfor 语句中未使用的组件的最大数量2023.1 最新变化