Yegor Bugayenko: 5 things to improve Java

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com

Yegor Bugayenko offers suggestions for making Java better:

Global Variables. There are Singletons in Java, which, as we all know, are nothing but global variables. Wouldn’t it be great to enable global variables in Java and get rid of Singletons. PHP, JavaScript, Ruby and many other languages have them, why doesn’t Java?

Global Functions and Namespaces
To group static methods together we create utility classes, where we have to define private constructors to prevent their instantiation. Also, we have to remember which particular utility class a static method is in. It’s just extra hassle. I’m suggesting we add global functions to Java and optional “namespaces” to group them.

Full Access to Private Attributes and Methods
In order to access a private attribute or a method of an object from outside we have to use the Reflection API. It’s not particularly difficult, but it does take a few lines of code, which are not so easy to read and understand.

NULL by Default
It would be convenient to let us call constructors and methods with an incomplete set of arguments. The arguments we don’t provide will be set to null by default. Also, when a method has to return something, but there is no return statement, Java should return null. This is almost exactly how it works in PHP, Ruby, and many other languages. I believe it would be a convenient feature for Java monkeys developers too.

Getters and Setters
I think it’s only obvious that we need this feature: every private attribute must automatically have a setter and a getter. There should be no need to create them, Java will provide them out-of-the-box, just like Kotlin and Ruby do. What is the point of having an attribute if there are no getters and setters to read it and to modify it, right?

These would go a long way to making Java more like other languages. I do wonder though, perhaps we should freeze Java and say “No more changes to this language”. There are so many innovative languages that run on the JVM. Perhaps all innovation should happen in these new languages, and Java should focus on stability?

Source