Can a Static Nested Class be Instantiated Multiple Times?

前端 未结 6 1094
别那么骄傲
别那么骄傲 2021-02-05 05:14

Given what I know of every other type of static feature of programming––I would think the answer is \'no\'. However, seeing statements like OuterClass.StaticNestedClass ne

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-05 05:34

    It is legal. The fact that the inner class is static gives you a benefit here; its instances are not bound to any instance of the containing class, so they can be freely instantiated (as long as the access qualifier allows it).

    The price, however, is that the inner class can't use non static members/methods of the containing class.

提交回复
热议问题