Advantage of Local Classes Java

后端 未结 3 1084
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 03:33

What is the advantage of local classes in Java or in any other language that makes use of this feature?

3条回答
  •  天涯浪人
    2020-11-29 04:00

    There are a number of things that you can do with local classes that you don't get with anonymous inner classes.

    • because the type has a name, you can more usefully add members not in the supertype
    • a given name can make stack traces easier to follow (particularly for lock objects)
    • subtype more than one base type
    • construct in more than one place, and multiple constructors

    On the other hand they make some hideously verbose syntax even messier.

提交回复
热议问题