Why can't inner classes declare static members?

前端 未结 5 484
清酒与你
清酒与你 2021-02-01 17:36

The Java Tutorial says that since an inner class is associated with an instance of the enclosing class, it (the inner class) cannot define any static members itself.

It\

5条回答
  •  攒了一身酷
    2021-02-01 18:11

    Basically just an arbitrary decision. there's no reason it couldn't be supported, but there is also not really any good reason to support it. just declare the static field in the outer class.

    also, that quote may not be entirely correct: i believe you can declare a static serialVersionUID in an inner class.

提交回复
热议问题