gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 16:58:18 25 4
gpt4 key购买 nike

假设我有在 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)/*-{
if (index == null) {
// well, index is null…
} else {
var i = index.@java.lang.Integer::intValue()();
// now 'i' is the int value of 'index'
}
}-*/;

关于java - 如何在javascript中将整数转换为int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29295380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com