Unit type?
Zhong Yu
zhong.j.yu at gmail.com
Thu Sep 12 23:20:28 PDT 2013
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