Unexpected equality behavior (java.lang.Long)

Tomáš Zíma tomas at tzima.cz
Thu Aug 4 23:08:58 UTC 2016


A classical beginner's mistake. You are using Java objects and comparing 
references, not the values, so this is expected behavior. Simply compare 
the objects using equals().

On 4.8.2016 15:48, João Paulo Varandas wrote:
> Hi guys!
>
> It seems that version 1.8.0_101 has a bug in equality for same java data
> types (java.lang.Long).
>
> Check that:
> jjs> new java.lang.Long(10) == new java.lang.Long(10)
> false
>
> Oops!?
>
> See the gist:
> https://gist.github.com/joaovarandas/51567bd3b576d48a4c574d60d5a60ba3
>
> The results for all types should be ...
> ==    true
> ===   true
> equals true
>
> But for java.lang.Long and java.math.BigDecimal:
> ==    false
> ===   false
> equals true
>
> Maybe we could expand the test to other classes too, but the issue ...
> - It does happen in 1.8.0_101.
> - It does not 1.8.0_91.
> - It does happen with other classes (BigDecimal).
> - It does not happen with String.
> - It does not happen with Integer.
>
>
> I understand this is not an expected behavior. For now I'm rolling back
> to 1.8.0_91 in my environments.
>
>
>
> Do you me to file a bug?
>
> Thanks
> J
>




More information about the nashorn-dev mailing list