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.

3
  • I disagree. A static method cannot access instance data because instance data must be accessed via an instance of the object and the static method is not associated with any given instance (but with the class definition). Commented Feb 28, 2017 at 11:53
  • You miss my point. If it's called from within the class the compiler could pass an instance pointer like it does when it's not a static class. The problem comes if it's called from elsewhere--which means private static methods could access instance data (albeit by internally basically ignoring the static.) Commented Feb 28, 2017 at 18:06
  • Yes, the compiler /could/ but why should it? Passing such a pointer essentially reduces it to an instance method. Your stipulation that it is only private methods that could do this is moot - Reflection technologies make /all/ methods accessible - private or not - making this an even more risky proposition. Our Friends in Redmond have gone in the other direction; their languages raise a warning if you try to call a static method against an object instance (and not the class itself). Commented Mar 1, 2017 at 11:31