Incident Report 9079511: Java Language Enhancement: Disallow access to static members via object references
Florent Guillaume
florent.guillaume at gmail.com
Wed Feb 4 22:24:52 UTC 2026
I'd like to add (too late) that this (and all the answers by this
"amazingcodewithus at gmail.com" which has no prior existence on the
internet) has all the hallmarks of an LLM and imho nobody should spend
time on it unless proved otherwise.
The discussion was somewhat interesting though :)
Florent
On Fri, Jan 23, 2026 at 1:42 PM Amazing Code
<amazingcodewithus at gmail.com> 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
>
> Compiler should produce an error when static members are accessed through object references.
>
> Error messages should explicitly guide developers to use class-based access.
>
> Rules should apply to static fields, static methods, and static nested types.
>
> 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
More information about the amber-dev
mailing list