Unit type?

Ali Ebrahimi ali.ebrahimi1781 at gmail.com
Fri Sep 13 00:07:26 PDT 2013


just workaround:

    interface VoidFoo extends Foo<Void>{
        default Void bar(){
            barV();
            return null;
        }
        void barV();
    }



On Fri, Sep 13, 2013 at 10:50 AM, Zhong Yu <zhong.j.yu at gmail.com> wrote:

> Have you guys discussed about introducing Unit type in Java? What's
> the thinking here?
>
> I'm looking at my code and I'm seeing a lot of `Foo<Void>`, `return
> (Void)null`, or doubling APIs to handle both T->R and T->void cases.
> This is becoming very ugly.
>
> While Void is a reasonable substitute for Unit in most use cases, it
> doesn't feel right to pass 'null' around; it doesn't sound right that
> a function yields a Void value.
>
> After lambda is released, people are going to desire a Unit type in
> their functional style code more than before. Maybe Java8 should ship
> with a Unit before it's too late? The current practice of using Void
> for Unit is probably not too wide spread; we have a chance to correct
> it now.
>
> If Java is determined to stick with Void down the road, can we at
> least define a constant for (Void)null? Something like Void.VOID, so
> that we can write `return VOID` and `x->VOID`.
>
> Zhong Yu
>
>


More information about the lambda-dev mailing list