I am wondering why I can use the method parameters i and j inside the lambda and where they are stored in the anonymous class. I also noticed the compiler automatically makes these parameters final. What's going on here in the background I am not aware of?
public class Editor {
public interface Task {
int edit();
}
static ArrayList<Task> tasks = new ArrayList<>();
public static void add(int i, int j) {
tasks.add(() -> i + j);
}
public static void main(String[] args) {
add(4,5);
System.out.println(tasks.get(0).edit());
}
}