如何在 javascript 中将整数转换为 int

How to Convert Integer to int in javascript

假设我在 GWT(JSNI) 的 Java 脚本中编写了方法,它接受包装数据类型 Integer 并且我需要在 JS 中转换为原始数据类型。

    public static native void nativeMethod(Integer index)/*-{
// how to check the null values
//how to convert into primitive type

}-*/;

有什么建议吗?

 public static native void nativeMethod(Integer index)/*-{
var converted 
if(index!=null){
    converted = Number(hindeIndex);
    }else{
    converted=null;
    }
}-*/;

这有效.. 进行了空检查,如果没有则将其转换为 var 类型

public static native void nativeMethod(Integer index)/*-{
  if (index == null) {
    // well, index is null…
  } else {
    var i = index.@java.lang.Integer::intValue()();
    // now 'i' is the int value of 'index'
  }
}-*/;