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

When script implements a Java interface, return value needs to be converted to closest Java type

XMLWordPrintable

    • b61
    • generic
    • generic

      By JavaAdapter feature, JavaScript can implement Java interface. When script implements a Java interface, return value needs to be converted to closest Java type. For eg. if script implements java.util.Comparator interface, then the return value of compare function should be converted to int.

      // a Comparator implementation that uses length comparison
      var x = new java.util.Comparator() {
          compare: function(o1, o2) {
             return o1.length - o2.length;
          }
      }

      In the above case, return value of compare method is int. So, script function's return value (of type java.lang.Double -- type used for all JavaScript numbers) should be converted to Java int (i.e., java.lang.Integer - the closest primitive wrapper type).

            sundar Sundararajan Athijegannathan
            sundar Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: