What are the purposes of inner classes

前端 未结 10 1868
终归单人心
终归单人心 2020-11-29 23:14

I am reviewing the concept of inner classes in java. so far from what I\'ve understood and applied java inner classes has a link or access to the methods and fields of its o

10条回答
  •  半阙折子戏
    2020-11-29 23:43

    This is a style question. Anything that can be done with an inner class can also be done as a as series of external classes. Inner classes are especially useful for classes that are lightweight or tightly bound to the enclosing class. For example, a comparator is frequently both these things. It needs intimate knowledge of the implementation of the class, and may only be a few lines long. It may be an ideal candidate as an internal class.

提交回复
热议问题