To add a concrete example, here is a Java collections library written by CERN
https://github.com/kzn/colt They make instances of classes specifically to allow static methods to create aliases https://github.com/kzn/colt/blob/master/src%2Fhep%2Faida%2Fbin%2FBinFunctions1D.java#L12 And this is done liberally throughout the library, as well as code which uses the library (which is reasonable to assume given that it was an intended usage pattern) private static final cern.jet.math.Functions F = cern.jet.math.Functions.functions; On Fri, Jan 23, 2026, 10:12 AM Red IO <[email protected]> wrote: > I understand your idea. But I think that's exactly what the warning is > for. It suggests people to not access static data through objects. Making > it an hard error would likely break many code bases requiring massive > migrations without any real benefits. > > Treating warnings as errors and annotating necessary warnings with > suppress warnings and a comment should be best practice anyway. > > Great regards > RedIODev > > On Fri, Jan 23, 2026, 13:42 Amazing Code <[email protected]> > wrote: > >> I am writing to propose a language enhancement regarding the handling of >> static member access in Java. >> *Issue* >> >> Java currently permits static fields and methods to be accessed through >> object references, despite static members belonging strictly to the class. >> This behavior is often misleading and can create confusion, especially in >> large codebases or among less-experienced developers. >> >> Example: >> >> MyClass obj = new MyClass(); >> obj.staticMethod(); // Currently allowed, but confusing >> >> *Proposed Enhancement* >> >> I request consideration of a change that *disallows access to static >> members via object references*, enforcing access exclusively through the >> class name. This would convert the current warning into a *compile-time >> error*. >> *Rationale* >> >> - >> >> Prevents misconceptions about instance vs. class-level behavior >> - >> >> Improves code clarity and consistency >> - >> >> Reduces maintenance complexity in enterprise applications >> - >> >> Encourages best practices already recommended by the community >> >> *Suggested Requirements* >> >> 1. >> >> Compiler should produce an error when static members are accessed >> through object references. >> 2. >> >> Error messages should explicitly guide developers to use class-based >> access. >> 3. >> >> Rules should apply to static fields, static methods, and static >> nested types. >> 4. >> >> Optionally, provide a compiler flag for backward compatibility during >> migration. >> >> *Conclusion* >> >> Restricting object-based access to static members would strengthen >> language clarity and help eliminate a common source of misunderstanding. I >> kindly request your consideration of this enhancement for future Java >> releases. >> >> Thank you for your time and continued work on the Java platform. >> >> Sincerely, >> *Kamlesh Kohli* >> >
