如题,搜索了下坛子里内部类的帖子,没看出来在实际使用上内部类一般可用于常用的哪方面,有点郁闷,特请教下?

解决方案 »

  1.   

    Each inner class can independently inherit from an implementation. Thus, the inner class is not limited by whether the outer class is already inheriting from an implementation.1.The inner class can have multiple instances, each with its own state information that is independent of the information in the outer class object.
    2.In a single outer class you can have several inner classes, each of which implement the same interface or inherit from the same class in a different way. 3.The point of creation of the inner class object is not tied to the creation of the outer class object. 
    4.There is no potentially confusing “is-a” relationship with the inner class; it’s a separate entity.
      

  2.   

    作为外部类的一种组件支持外部类,比如java.util.Map和java.util.Map.Entry的关系
    也可以定义一个函数对象来开展一个任务,比如java.util.TimerTask经常做一个匿名内部类。
    也可以模拟多重继承
    可以隐藏实现细节其他还有些,用得少
      

  3.   

    你看看SWING这部分内容就明白了.
      

  4.   

    thinking in java 3rd的第8章,内部类于控制框架那小节有个简单的使用内部类的例子,你可以先看看那个