Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 4
    I'll buy your explanation for static properties of the inner class, but as @skaffman points out in a comment to my answer, what about static methods? It seems as though methods should be allowed without mandating that they be detached from any instance. Indeed, in java, you can call static methods on instances (although it's considered bad style). BTW: I asked a colleague to attempt to compile the OP's code as C# and it does compile. So C# apparently allows this which demonstrates that what the OP wants to do doesn't violate some fundamental OO principle. Commented Dec 23, 2009 at 18:19
  • 3
    Happens exactly the same with the methods. The point here is not the attributes or the methods being statis or not, but the fact the inner class it self being instance "stuff". I mean, the problem here is that an instance of such inner class doesn't exists until the outer class is created. Hence what method would be dispatched then if there is nothing. You would hit air only because you'll need an instance in first place. Commented Dec 23, 2009 at 18:29
  • 1
    About C# ... well. It is not OO valid just because C# allows it, I don't mean it is wrong, but C# includes several paradigms to make the development easier even at cost of consistency ( you have to learn new things with each .NET release ) and it allows this and other kinds of things among others. I think that's a good thing. If the community feel an extra feature is cool enough C# may have it in the future. Commented Dec 23, 2009 at 18:32
  • 3
    @OscarRyz Why do you need instances of the inner class to use its static methods/fields? And an example of [useful] static method in inner class is private helper method. Commented Dec 4, 2014 at 9:55
  • 2
    With use of final , static fields is allowed in inner class in java. How do you explain this scenario ? Commented Jul 9, 2018 at 2:10