The philosophy of Nothing

tronicek at tronicek at
Sun Nov 29 21:25:33 PST 2009

Hi Paul,

as far as I know, Nothing is used only by compiler. And I do not see any
benifits if I was allowed to use it as an ordinary type in my code.

What is the primary purpose of Nothing?
Look at closure #() { throw new AssertionError(); }
Compiler must infer the return type here. But what it should be?
It can be anything because the closure never returns normally.
So, compiler will use Nothing which is a subclass of any type.

Zdenek Tronicek
FIT CTU in Prague

Paul Benedict napsal(a):
> Thanks Neal. Reiner, your explanation was very good.
> So basically Nothing can be used outside of closures:
> public Nothing throwMe(RuntimeException t) {
>     throw t;
> }
> 1) Does the Java compiler have to prove a method can never return
> normally?
> 2) What is the benefit of telling the compiler the method *must* throw
> an Exception? Don't say read the spec :-) I did, but it's sparse on
> the purpose
> 3) For a method that returns Nothing, if a class transformer alters
> the method body and actually issues a return, what happens? is a JVM
> Error thrown?
> Paul

More information about the coin-dev mailing list