如何从Java JNI获取原始类型的类

时间:2013-04-08 03:34:52

标签: java java-native-interface

这个问题与这个问题及其答案有关:

Does int.class equal Integer.class or Integer.TYPE in Java?

由于int.class不等于Integer.class,如何通过JNI在本机级别获取int.class类或其他原始类型?我需要指向int.class的jclass对象而不是Integer.class。

2 个答案:

答案 0 :(得分:4)

此测试

    System.out.println(Integer.TYPE == int.class);

打印true。也就是说,Integer.TYPE就是你想要的,你可以从本机代码中读取Integer.TYPE字段。或者从本机代码中调用Class.getPrimitiveClass("int")

答案 1 :(得分:1)

在JNI中,原始值作为实际机器值传递。 int作为jint传递,它是对32位有符号整数的typedef。

http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/types.html#wp9502

相关问题