示例:
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);
}
}
for
语句中未使用的组件的最大数量2023.1 最新变化