JDK-8163945 : Honor Number type hint in toPrimitive on Numbers
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2016-08-12
  • Updated: 2017-11-29
  • Resolved: 2016-08-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
8u152Fixed 9 b133Fixed
Since JDK-8143896 not all instances of java.lang.Number are treated as primitive numbers anymore in Nashorn. This affects java longs/Long and all classes implementing java.lang.Number that do not directly represent wrappers of Java primitives.

However, these Number objects should still convert to JS numbers when passed to the ECMAScript ToPrimitive with Number hint. This would allow to compare these objects numerically in <, <=, >=, and > operators. 

Currently, the code below prints "false" because Longs are converted to strings:

l1 = new java.lang.Long(2), l2 = new java.lang.Long(10);
print(l1 < l2);