Effective Java : Making a class as private nested class (Item 22)

This question already has an answer here:

  • Java inner class and static nested class 23 answers

  • When I read that book, I took that paragraph this way:

    If a class is used by another class and there is no other way it would be used by some other class by any means, move it to the class that uses it as an inner class. This usage renders the inner class as a "private" feature of encapsulating class. Therefore, in order to keep things tidy, somewhat similar to encapsulation, the writer advised to make the move.

    From that point of view, it made sense to me.

    In short, encapsulate where ever it makes sense but don't force it if it does not.

    链接地址: http://www.djcxy.com/p/92026.html

    上一篇: Thread.FreeOnTerminate:=真,内存泄漏和鬼运行

    下一篇: 有效的Java:将类作为私有嵌套类(第22项)