Default value for date/time

Stephen Colebourne scolebourne at joda.org
Wed May 9 00:37:35 UTC 2018


On 9 May 2018 at 01:13, John Rose <john.r.rose at oracle.com> wrote:
>> I worry that while the key principle has got the project a long way,
>> it is too hard line when it comes to some potential value types -
>> Currency or Money being other examples where a default is silly, but
>> they are otherwise fully value-like.
>
> Any value type measuring a scaled amount is going to have a
> zero right?  That's the default, probably.  It's affine amounts
> like times that don't have a good default.

Whats the default Currency? USD is a not an acceptable answer. Money
is the same as it can't exist without a currency.

What about a Distance object? Is it measured in Miles or Kilometers by default?

> class ObserveTheDefault {
>    LocalDateValue x;
>    LocalDateValue[] a = new LocalDateValue[1];
>    void test() {
>      System.out.println(x);
>      assert(LocalDateValue.default.equals(x));
>      System.out.println(a[0]);
>      assert(LocalDateValue.default.equals(a[0]));
>    }
>    public static void main(String… av) { new ObserveTheDefault().test(); }
> }

My suggestion was that code does not compile as `LocalDateValue x`
wasn't assigned in the constructor (not "works like an int", but then
its not like an int). Anything else risks allowing a "null-like"
LocalDate to escape and head off causing havoc to real code - just
like null does...

Anyway, I'm not expecting firm/final answers right now - value types
has too far to go. Consider my points to be concerns that might be
worth considering.

thanks
Stephen


More information about the valhalla-dev mailing list