Rec 05
Problems
01. Stack and Heap with nested class
In the Static nested class,
thisis as long as it is used in a non-static method.When accessing the captured variables, don't need any
thisor what.Variable capture will also capture the instance that invokes the method where the local class comes from.
For example, the stack frame at Line A for the following code is as follows,
class B {
int x = 1;
void f() {
int y = 2;
class A {
void g() {
B.this.x = y; // <--
}
}
A a = new A();
// Line A
a.g();
}
}
02. Write an immutable class
Make fields/class
finalThe class which extends from the immutable class may not be an immutable class.
Tips
Make fields/class
finalThe class which extends from the immutable class may not be an immutable class.
In the Static nested class,
thisis as long as it is used in a non-static method.When accessing the captured variables, don't need any
thisor what.Variable capture will also capture the instance that invokes the method where the local class comes from.
Last updated