Link Details

Link 19090 thumbnail
User 108814 avatar

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."
  • 13
  • 0
  • 1495
  • 420

Comments

Add your comment
User 215453 avatar

jsav replied ago:

0 votes Vote down Vote up Reply

I'm already setting @edu.umd.cs.findbugs.annotations.DefaultAnnotation(NonNull.class) for all classes...

User 190346 avatar

ilazarte replied ago:

0 votes Vote down Vote up Reply

I used to hate null response, but I've grown to really like it. what is so hard about "if (blah == null)"?

User 108814 avatar

aj16780 replied ago:

0 votes Vote down Vote up Reply

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;
}

User 108814 avatar

aj16780 replied ago:

0 votes Vote down Vote up Reply

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. :-)

User 182143 avatar

mezmo replied ago:

0 votes Vote down Vote up Reply

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.

User 190346 avatar

ilazarte replied ago:

0 votes Vote down Vote up Reply

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.

User 108814 avatar

aj16780 replied ago:

0 votes Vote down Vote up Reply

> 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.

User 60102 avatar

jodastephen replied ago:

0 votes Vote down Vote up Reply

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!

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (13)



Voters Against This Link (0)