Unit type?

Zhong Yu zhong.j.yu at gmail.com
Mon Sep 16 10:16:19 PDT 2013


On Mon, Sep 16, 2013 at 5:13 AM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>
> On Sep 14, 2013, at 3:55 AM, John Rose <john.r.rose at oracle.com> wrote:
>
>> On Sep 13, 2013, at 6:19 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:
>>
>>> public class Void
>>>
>>>   /** a constant for (Void)null */
>>>   public static final Void VOID = (Void)null;
>>
>> I like that; it's as concise and better typed than "return null".  How many occurrences of null in the JDK could be be replaced by VOID, today?
>>
>
> FWIW my IDE reports 264 usages of Void method return type and 471 usages as a type parameter in JDK code (including tests). Very few (Void)null casts are used.

"return null" in a Void method body is perfectly fine. However in a
lambda body javac sometimes has to infer the return type from return
values, a bare "null" is too vague, both for javac and for human
readers. If we predict that a lot of Void lambda expressions will be
written in time to come, "(Void)null" will become a lot more common
than it is now.

Zhong Yu

>
> Paul.
>
>
>


More information about the lambda-dev mailing list