[records] equality on float / double components
scolebourne at joda.org
Thu Dec 7 11:11:51 UTC 2017
Float.equals() every time.
Beans/values/records are about state. Two beans/values/records that
are .equals() must be fully substitutable, thus Float.equals() is
On 6 December 2017 at 18:07, Brian Goetz <brian.goetz at oracle.com> wrote:
> It's time to play everyone's favorite game show, "What about NaN".
> If we have a record:
> record Foo(float f);
> We would like Object.equals() to be reflexive, symmetric, and transitive.
> But if we define equals() in the obvious way (delegating to float==), then
> `new Foo(Float.NaN`) would not be equal to itself.
> If we delegate instead to `Float.compare(this.f, that.f)`, the NaN problem
> goes away (though comparison becomes modestly more expensive), but now +0
> and -0 are distinguished (== treats them the same.)
More information about the amber-spec-observers