Arne Vajh?j wrote:
Seamus MacRae wrote:
Arne Vajh?j wrote:
Seamus MacRae wrote:
Thomas A. Russ wrote:
Seamus MacRae <smacrae319@live.ca.nospam> writes:
Adlai wrote:
You can have a function that returns some data, or
NIL if the data is unavailable.
Java can do this (return an object or null), and java.util.Map.get()
does it and is in the standard library.
Um, how does this work if you want the Java method to return a
literal
such as int or double? I guess you are then forced to wrap the
return
type in the corresponding Integer or Double
Pre-Java 5:
public Integer returnOneOrNull () {
if (foo) return Integer.valueOf(1);
return null;
}
Java 5 and later:
public Integer returnOneOrNull () {
if (foo) return 1; // An int literal is returned.
return null;
}
Nice try. Next time you want to pick a fight with someone, read more
carefully and choose your target more carefully, or better yet, think
better of it and just go on about your business.
I think you should read more carefull yourself.
I think you should shut up before you sink any deeper. You're in
quicksand. Or hadn't you noticed?
The above just proved that you have not even understood what
is being discussed.
It proved nothing of the sort. Perhaps if you'd focus on Java instead of
insults you would avoid these kinds of embarrassments, Arne.
The point is that it needs to be:
Integer returnOneOrNull()
not:
int returnOneOrNull()
to be able to return null.
That is irrelevant. The person asked how does it work if they want to
"return a literal". Formerly you had to wrap it, for instance new
Integer(3) or Double.valueOf(42.0). Now you can just "return 3;" or
"return 42.0;".
No.
return null.