Why there is no static class in Java

前端 未结 5 812
死守一世寂寞
死守一世寂寞 2021-01-14 16:52

I am new to java. When I was going through language specification I found that static classes cannot be declared, but we can have static inner classes. I am little confused

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-14 17:47

    AFAIK,if it will allow the top level classes to be declared as static class then it will hold the reference in the heap memory all the time even when you are not using it.and that is what called Memory Leak.so that is why it is restricted to do so.

提交回复
热议问题