. , "this" ( ).
, . private, . :
public class MyClass {
private static class MyInner {
private void myMethod() {
new Thread(new Runnable() {
public void run() {
while (true) {
System.gc();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
System.out.println("Inner class still alive! "+this);
}
}
}).start();
}
}
public MyClass() {
new MyInner().myMethod();
}
protected void finalize() throws Throwable {
System.out.println("MyClass has just been finalized");
super.finalize();
}
public static void main(String[] args) {
new MyClass();
}
}
: , , MyClass, MyInner!
. finalize() , , , .