Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8163945

Honor Number type hint in toPrimitive on Numbers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • None
    • core-libs
    • None
    • b133
    • generic
    • generic

        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);

              hannesw Hannes Wallnoefer
              hannesw Hannes Wallnoefer
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: