The philosophy of Nothing
tronicek at fit.cvut.cz
tronicek at fit.cvut.cz
Sun Nov 29 23:08:03 PST 2009
Minor clarification: type is inferred so that the closure can be converted
to an interface type. For example:
#() { throw new NullPointerException(); }
is converted to
interface X {
Nothing invoke() {
throw new NullPointerException();
}
}
The type checking is done after the conversion.
As for the type inferred "Object", it can be done this way. Then, the
closure would have been converted to
interface Y {
Object invoke() {
throw new NullPointerException();
}
}
The original motivation for Nothing (Unreachable then) was to enable
passing a closure which returns void as argument to the method like
static <T> T withLock(Lock lock, #T() block)
Z.
--
Zdenek Tronicek
FIT CTU in Prague
Paul Benedict napsal(a):
> Zdenek,
>
> Thank you for your patience. Is this use case any different than
> reflection or dynamic languages? It sounds like the "Nothing" type
> returns an Object and automatic casting is performed. So why don't we
> just use Object as the return value and force a cast?
>
> Paul
>
> On 11/30/2009 12:33 AM, tronicek at fit.cvut.cz wrote:
>> They should compile because Nothing (the type inferred) is a subtype of
>> Integer and String.
>> If the type inferred was void, they should not have compiled.
>> So, Nothing enables the compiler to check types as it does in any other
>> cases.
>>
>> Another example:
>>
>> static<T> T m(#T() p) {
>> return p.invoke();
>> }
>>
>> Integer i = m(#() { throw new AssertionError(); });
>> String s = m(#() { throw new AssertionError(); });
>>
>> new ArrayList().add(#() { throw new AssertionError(); });
>>
>> Z.
>>
>
>
More information about the coin-dev
mailing list