When working with Oracle's JDK 1.8.0_121 and using Nashorn (the JavaScript engine integrated into the JDK), the comparison new BigDecimal(1.0) === 1
returns false
, while new BigDecimal(1.0) == 1
returns true
:
By utilizing JDK 1.8.0_121's jjs
(Nashorn REPL):
jjs> var BigDecimal = Java.type("java.math.BigDecimal")
jjs> var bd = new BigDecimal(1.0)
jjs> bd
1
jjs> bd === 1.0
false
jjs> bd == 1.0
true
When using JDK 1.8.0_74's jjs
:
jjs> var BigDecimal = Java.type("java.math.BigDecimal")
jjs> var bd = new BigDecimal(1.0)
jjs> bd
1
jjs> bd === 1.0
true
jjs> bd == 1.0
true
Is this change in strictness rules for equality in Nashorn documented? Is there a specific definition of the ===
strict equality operator in Nashorn that could explain this behavior change?
Alternatively, could this be a flaw in the JDK?