W***o 发帖数: 6519 | 1 看了core java这本书里的inner class部分,觉得很糊涂啊,有没有大侠能指点一下,
理清一下思路。这个除了能access private field和variable,还能干啥?主要是干什
么用的?谢谢 | p*****2 发帖数: 21240 | | W***o 发帖数: 6519 | 3 谢谢二爷您嘞
【在 p*****2 的大作中提到】 : 你说的这两个好处就已经很方便了。
| s******e 发帖数: 493 | 4 four types:
static inner class: really should not be called inner class, especially
public one. I hardly find it useful But I did see somebody uses it to
emphasize the domain relationship.
inner class: mostly be used for event listeners or for limiting publication
scope to the enclosing class. Occasionally it might escape from class scope.
method local inner class: never use it. you use it when you really want to
limit it's life scope. It is the preferred question for an interview: about
what kind of variables you an access from it.
anonymous class: can be at class, object or method level. used a lot for
event listeners especially in Swing. | z*******3 发帖数: 13709 | |
|