Java Learning Note – inner class(2)
Reference: Java Tutorial (Oracle)
| Meaning | Characters |
| |
Inner class
|
help the outer class to realize some function (ex. iterator of Array)
| 1.inner class can be viewed as a member of an instance outer class, hence, it must depend on an instance. (no static allowed)
2.inner class method with be covered by the outer class same name method. (use this.field to access inner class members, and OuterClass.this.field to access outer class members)
3.it can realize a interface, the outer class return such an interface.(???) |
| |
Static inner class | same as static class member | 1.it can only access static outer member
2. have no illustration to outer class |
| |
Local inner class | class in a block
| 1.it can access final variables in the method where it was stated ( because local inner class will die when the method finished) | ||
Anonymous inner class |
| 1. used when an instance of class is needed |