in java-samples/src/main/java/com/jetbrains/inspections/PatternMatchingForInstanceOf.java [65:81]
public void examplesOfUpdatesToPatternMatchingInJava16(Person person) {
if (person instanceof Employee employee) {
// in #JDK16 you can change this pattern variable - IntelliJ IDEA marks mutated variables with underline
employee = new Employee();
if (employee.isBasedInOffice()) {
employee.workFromHome();
}
}
// in #JDK16 you will need to mark this as final if you don't want it to change
// if a variable is final or effectively final, IntelliJ IDEA does not underline it
if (person instanceof final Employee employee) {
if (employee.isBasedInOffice()) {
employee.workFromHome();
}
}
}