Unit type?

Remi Forax forax at univ-mlv.fr
Fri Sep 13 06:03:11 PDT 2013


On 09/13/2013 08:20 AM, Zhong Yu 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
>

We discussed about allowing the compiler to insert 'return null' when 
the return type is Void,
but because it was not a change related to lambda by itself, this item 
did not
find its way to the final list.

that's said it's a good feature for a coin2 project IMO.

Rémi




More information about the lambda-dev mailing list