Java inner classes and static methods or fields -


why can't inner classes have static (non-final) fields , methods?

this question has been posted before posted answers were: it's design decision or because inner classes happen in context of outer class , cannot declare static methods.

yet these answers not clarify question. consequences of allowing static fields , methods on inner classes? guess both restrictions connected. since static methods require access other static methods , non-final static variables of inner class or outer class (to able change internal states), lead inner class behave static one. jvm limit access static methods in inner classes static methods , data inside inner class, though. yet raises question: why can't declare static non-final variables inside inner classes?

is design or there problems?

kind regards

declaring static variables in non-static inner class seems contradictory intend of creating inner non-static class.
if declaring variables , methods static when make sense access them without creating instance of class, if declaring inner class non-static instance type, intent access via instance not staticly. if declare inner class static, therefore separate outer class, can declare variables , methods static.
asked consequences if java allowed declare static methods/fields in inner non-static classes. there none. doesn't make sense, therefore it's design choice.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -