Example:
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);
}
}
Can be replaced with:
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);
}
}
This inspection only reports if the language level of the project or module is 20 or higher
for
statementNew in 2023.1