The Philosophy of Nothing
Paul Benedict
pbenedict at apache.org
Mon Nov 30 22:31:06 PST 2009
Neal,
2) Outside of the whole closure conversation, can java.lang.Nothing be
used? And is there value in it? For example:
>
> class Test {
> public Nothing throw_it() {
> throw new AssertionError();
> }
> }
>
>
> Yes, but the most important use cases arise with closures.
Java existed all this time without caring whether methods complete or
not. Neither Java reflection, dynamic language support, or JSR-292 has
had a pressing desire to know this. Are we sure this is a good
advancement in the language design? Aside from closure support, what is
the value in saying a method returns Nothing?
> 3) In regards to byte-code manipulation, what would happen at
> runtime if a class transformer takes the body of method that
> cannot return normally ("returns" java.lang.Nothing) and actually
> returns? The opposite case must be considered too. Would a JVM
> error be thrown?
>
>
> Yes. It would be a NullPointerException at the call site (that's the
> only value the verifier would let be returned from a Nothing-returning
> method). The opposite case (failing to return from a method) isn't an
> issue.
I don't think NPE is very descript in this situation or useful in
helping debugging. I think the error goes beyond bogus pointers and into
something more deep. Can you consider a new Exception for this?
Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/closures-dev/attachments/20091201/24360ae1/attachment.html
More information about the closures-dev
mailing list