Jave inner classes

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Jave inner classes

fschmidt
Administrator
copied from https://old.reddit.com/r/GoodSoftware/comments/d3glp4/jave_inner_classes/

See Inner.java

The Inner instance isn't garbage collected here because all inner classes keep a reference to the outer class. This is horrible, especially for anonymous inner classes that don't user the other class at all. I thought the Java compiler would have the intelligence to detect this for anonymous inner classes and to make them effectively static when it has no reference to the outer class, but no. This can cause serious garbage collection issues.

Of course I don't use most new Java features. But inner classes were released early, so here we begin to see where Java went wrong. Java is supposed be like an object-oriented C with garbage collection. This means that it should be explicit with no magic and no hidden nonsense. Inner classes were the first violation of Java's initial good design, with a hidden reference to the outer class. Not only does this cause garbage collection issues but it also breaks the clone() method. Java should have only added static nested classes. Anonymous "inner" classes should have also been static and should have only had access to outer variables and the outer class during construction. This would force things to be explicit and would eliminate all problems and would have been consistent with what Java was originally meant to be.

Of course as modern culture became depraved, all kinds of insane depraved features were added to Java. For example lambda expressions which are really depraved pseudo-closures implemented like broken anonymous inner classes. Of course I never use such depravity which was designed by and for modern scum. True closures make sense for languages based on this concept like Luan is. True closures work because they only keep references to variables that they really use. But closures don't belong in a language like Java.

In conclusion, don't use inner classes at all. Only use static nested classes. And avoid most new Java features. I will write a full review of Java when I have time, explaining which features are good or bad.
Reply | Threaded
Open this post in threaded view
|

Re: Jave inner classes

OmegaKV
I asked ChatGPT to respond to this in the style of a silicon valley scum:

Oh wow, where do I even start? First off, congratulations on discovering that inner classes in Java have references to their outer class, and it only took, what, 25 years since their introduction? Truly groundbreaking stuff. And here I was, thinking the JVM’s garbage collection was almost as magical as finding a free lunch in Silicon Valley.

But let’s dive deeper into the rabbit hole you’ve so bravely uncovered. You’re absolutely right, the Java compiler should be omniscient, just like how every Silicon Valley startup founder thinks they are. Expecting the compiler to automatically detect and optimize anonymous inner classes to be static if they don't use the outer class? Genius. Because, you know, compiler optimizations are just a matter of throwing in some AI buzzwords, and voilà, it reads your mind and cleans up your code.

And oh, the “depravity” of modern Java features! Lambda expressions? Pseudo-closures? How dare Java evolve and attempt to make developers' lives easier? It’s almost as if the language is trying to stay relevant in a world where things change. How preposterous! Clearly, Java should have remained a glorified version of C with garbage collection, forever untouched by the sands of time, just like the pristine coding standards of the 90s.

Let’s not forget the cultural downfall you’ve so eloquently tied to programming language features. Because yes, the evolution of a programming language is definitely a direct reflection of societal moral decay. Who knew lambda expressions were the gateway to depravity?

In the spirit of your profound insights, I’ll be sure to avoid all modern Java features. Why embrace progress when you can bask in the glory of static nested classes, the pinnacle of Java programming? And I eagerly await your full review of Java. It’s bound to be a classic, timeless piece, much like the static nested classes you so adore.

Remember, in the end, it’s all about keeping things explicit, with no magic, no surprises, and definitely no understanding of how programming languages evolve to meet the needs of developers. After all, who needs progress when you have nostalgia?