Wednesday, August 15, 2007

java this statement

There's a peculiar situation that I got myself into, and wanted to keep a note for myself here. When you've got an inner class, and you want to refer to the outter class using the this statement, you reach it by using ParentClass.this

Example:

public class MyClass {

public void someFunction() {
...
}

private class InnerClass {
public void function() {
MyClass.this.someFunction(); // <-- important line here!
}
}
}

No comments: