Java is now nearly 14 years old, and the age is starting to show. In my industry (banking), we joke that Java is the COBOL of the 21st century; except it's not much of a joke, it's the sad reality.
Java has a lot of "baggage" that is kept for backwards-compatibility -- exactly the kind of stuff that is critical for clients like banks. But I often think that it's high time for a reboot. Just read "Java Puzzlers" to find a list of pain-points in the language design. I'm not blaming the language designers -- a lot of lessons were learned in the past 14 years! However, I would really love some major changes that will happily break backwards compatibility while making the language much better.
Here is a (very partial) list of things I'd change in the language:
- Drop all deprecated items. It's high time Thread.stop and friends, for example, will die.
- Disallow overloading. It was a mistake. (I know this one is a bit controvertial, and yet...)
- Constructors must be private, only. Static methods should be used as factory methods to obtain instances. This allows for major and important optimizations. (Again, controvertial, but the academic community seems to agree. See also Item 1 in Effective Java.)
- Drop dead/mis-designed parts of the API. In particular, fix the Date class.
- Drop "finalize".
- Drop support for "raw" variants of generic classes. No more
List
; it has to beList<Something>
. - Properties. And no non-private fields while you're at it.
- Provide a default implementation of "equals" that iterates over fields and invokes their "equals"; allow some annotation ("@NonState") to mark fields that are not part of the equality test.
- "==" should invoke equals(); add a new operator, "is", for identity.
- Remove "clone" from Object; only objects that implement Cloneable should have this method.
- Allow a special annotation for test classes; test classes should be able to access private members of all classes in the same package.
- Make good use of Enums in the library -- curerntly, a lot of older classes use int constants instead.
- Drop "Thread.run"; Thread.start should accept a Runnable object (you'll be amazed at the number of bugs I've seen where Thread.run is called instead of Thread.start).
That's just off the top of my head... So, I'd like to hear:
- Do you agree that a reboot of Java (a new version breaking compatibility with old code) will be a good thing?
- What are your pet peeves, things you believe need fixing in the language? My own examples focused on compability-breaking items -- things you just can't do in current Java without breaking existing code. But other ideas are also welcome.
Clarification: I'm not looking for a new language (like Scala or C#). I'm looking for something that is clearly still Java -- but requires some porting effort for existing code. Note that for many of the changes I've suggested, code can be ported automatically or semi-automatically. I know banks won't adopt it any time soon (hey, I work there) but I also know that banks often start new projects, and would love to take advantage of existing programmers' knowledge while enjoying a better language.
To all those claiming that, for many of my suggestions, the team can just enforce its own rules (e.g., no overloading): true enough, but we're highly dependent on third-party code. Isn't everybody?