Unexpected equality behavior (java.lang.Long)
João Paulo Varandas
joaovarandas at inpaas.com
Fri Aug 5 01:43:40 UTC 2016
Sorry Tomas.
Either you did not read the message(which would be indeed a beginner's
mistake), or you are misleading the discussion.
What you said, about equality and references would be true if we were
talking about Java code. This is jdk8-nashorn's mailing list and I'm
talking about JavaScript evaluation inside the JVM.
Comparison operators inside the script engine follow JavaScript rules and
not Java rules.
*João Paulo Varandas*+55 11 99889-2321
joaovarandas at inpaas.com
2016-08-04 20:08 GMT-03:00 Tomáš Zíma <tomas at tzima.cz>:
> 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
>>
>>
>
>
--
"Esta mensagem, incluindo seus anexos, pode conter informacoes
confidenciais e privilegiadas.
Se voce a recebeu por engano, solicitamos que a apague e avise o remetente
imediatamente.
Opinioes ou informacoes aqui contidas nao refletem necessariamente a
posicao oficial da Plusoft."
"Antes de imprimir, pense em sua responsabilidade e compromisso com o MEIO
AMBIENTE"
More information about the nashorn-dev
mailing list