Java (anonymous or not) inner classes: is it good to use them?

后端 未结 15 2323
鱼传尺愫
鱼传尺愫 2020-12-01 06:48

In some of my projects and in some books was said to not use inner class (anonymous or not, static or not) - except in some restricted conditions, like

15条回答
  •  误落风尘
    2020-12-01 07:24

    Inner classes are often used to "pass a behavior" as a parameter of a method. This capability is supported in an elegant way by other languages with closures. Using inner classes produces some not elegant code (IMHO) because of a language limitation but it's useful and widely used to handle events and blocks in general with inner classes.

    So I would say that inner classes are very useful.

提交回复
热议问题