The philosophy of Nothing
Paul Benedict
pbenedict at apache.org
Sun Nov 29 21:53:22 PST 2009
Zdenek,
Is a problem present if the compiler were to infer it as void?
When I put these side-by-side, I don't see any particular issue.
closure #() { throw new AssertionError(); }
public void something() { throw new AssertionError(); }
You can write code today that never returns -- my second example.
Paul
On Sun, Nov 29, 2009 at 11:25 PM, <tronicek at fit.cvut.cz> wrote:
> 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.
>
> Z.
> --
> 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