By aj16780
via users.encs.concordia.ca
Published: Apr 17 2007 / 14:42
" The apparent trend in the evolution of languages supporting pointers would seem to indicate that the time is ripe to consider a switch in Java from nullable-by-default to non-null-by-default."
Comments
jsav replied ago:
I'm already setting @edu.umd.cs.findbugs.annotations.DefaultAnnotation(NonNull.class) for all classes...
ilazarte replied ago:
I used to hate null response, but I've grown to really like it. what is so hard about "if (blah == null)"?
aj16780 replied ago:
The problem with "if (blah == null)" is that every object reference in Java is a possible null pointer.
If we could state which variables can be null, we would get rid of thousands of unecessary null pointer checks - and all null pointer exceptions.
In Nice language, you define which variables might hold a null pointer and you can't use them before a null check:
public int exampeNullParameter(?String nullableParam) {
return nullableParam.length(); // <- compiler error!
}
public int anotherExample(?String nullableParam) {
if (nullableParam != null) {
return nullableParam.length(); // <- compiles
}
return 0;
}
aj16780 replied ago:
Forgot to mention: There's a feature request in Java bug database for this functionality:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5030232
Let's get votes for it. :-)
mezmo replied ago:
I have to admit to a prejudice here, I thought annotations were a mistake to begin with, still do, but while I find the syntax tedious this at least has some merit as a suggestion.
ilazarte replied ago:
objects can be null, again so what? strings can be empty, numbers can be 0 or -1; your application ususally abstracts away these issues. it's a very tiny thing to go after.
actually it's kind of laughable- do people spend all day checking for null instances? lol.
aj16780 replied ago:
> objects can be null, again so what?
They don't need to be. It would save us from lots of runtime bugs, time and effort.
I think if something can be done better, it should.
jodastephen replied ago:
I believe that null/notnull is a fundamental part of the language that is not well served. Unfortunately, I see annotations as a hack to solve the problem. I discussed here - http://jroller.com/page/scolebourne?entry=java_7_null_safe_types - some of the issues in extending Java to include it. PS. try to read the idea, not the syntax!
Voters For This Link (13)
Voters Against This Link (0)