IMHO What Java lacks
Up to this day, I have coded in Java for more than 6 years. Of course, I enjoy Java, its compilation engine, and above all: with Java I need not handle pointers myself, which is a great progress (I suffered a trauma when I was younger, with C/C++ pointers).
Thanks to Java 5 (Tiger), many improvements are now available. Among them, the most I use are generics and the new for loop, ala foreach.
Nonetheless, I think Java lacks some features I encountered in other languages. Of course, I admit that implementing new features into such a complex project like the JVM is a hard issue. But I throw my ideas, may Sun developers feel free to accept or reject them.
- Multiple heritage is impossible.
- Default parameters values are unavailable:
public Toto(int i, String sz){ // do something } public Toto(){ this(0, “tata”); } public Toto(int i){ this(i, “tata”); } public Toto(String sz){ this(0, sz); }
In PHP (or Python), all these functions may be summed up to:
[php] function Toto(i = 0, sz = "tata"){ // do something }
- Exception handling is too robust:
Let’s consider this function:
[java] public void toto() throws Exception1, Exception2, Exception3, Exception4{ // do something }
Now, in Java we need to catch the exceptions like this:
[java] public void tata() throws Exception4{ try{ toto(); } catch(Exception1 e1){ e1.printStackTrace(); } catch(Exception2 e2){ e1.printStackTrace(); } catch(Exception2 e2){ e1.printStackTrace(); } // throws the uncaught Exception4 }
Obviously, we can catch a generic java.lang.Exception, but let’s acknowledge there is more elegant way :-(( I would like to have this code:
[java] public void tata() throws Exception4{ try{ toto(); } catch(Exception1, Exception2, Exception3 eee){ eee.printStackTrace(); } // throws the uncatched Exception4 }