Survey on primitive type test patterns

Stephen Colebourne scolebourne at joda.org
Mon Nov 6 14:55:02 UTC 2017


On 3 November 2017 at 16:53, Brian Goetz <brian.goetz at oracle.com> wrote:
> Given:
>     Long zl = 0L;
>     Byte zb = (byte) 0;
> We have
>     zl == 0
> and
>     zb == 0
> but not
>     zl == zb

But given this:

    long zl = 0L;
    byte zb = 0;

My view is that this:

    zl == zb

should be rejected by the compiler. It is not in fact rejected by
Java, but that is a mistake. Other languages do reject similar,
forcing manual conversion between different size primitives (manual
conversion in this case is a good thing IMO).

I'm not sure the rest of the analysis takes that POV into account (is.
its not zero, but a long zero and a byte zero, the type matters in
comparisons). However, I do agree that #3 (punting) is probably a
reasonable way to go for now.

Stephen


More information about the amber-spec-observers mailing list