jclass和jobject的迷惑
第一次使用JNI,实例引用(jobject)和类引用(jclass)让人觉得很困惑。
实例引用与一个数组和java.lang.Object类或它的子类的实例对应。类引用与java.lang.Class实例对应,它代表着类的类型。
一个操作如GetFieldID,需要参数jclass,是一个类操作,因为它从一个类中获得field的描述。与此相反,GetIntField需要参数jobject,这是一个实例操作,因为它从这个实例中获得这个field的值。在所有的JNI方法中jobject和实例操作的结合和jclass和类操作的结合保持一致。所以是很容易记住类操作与实例操作的不同的。

Confusing jclass with jobject
The differences between instance references (a value of the jobject type) and class references (a value of the jclass type) can be confusing when first using the JNI.
Instance references correspond to arrays and instances of java.lang.Object or one of its subclasses. Class references correspond to java.lang.Class instances, which represent class types.
An operation such as GetFieldID, which takes a jclass, is a class operation because it gets the field descriptor from a class. In contrast, GetIntField, which takes a jobject, is an instance operation because it gets the value of a field from an instance. The association of jobject with instance operations and the association of jclass with class operations are consistent across all JNI functions, so it iseasy to remember that class operations are distinct from instance operations.

转自:http://blog.163.com/weidao_xue/blog/static/204541046201281825256656/

jobject和jclass的更多相关文章

  1. NDK(5) Android JNI官方综合教程[JavaVM and JNIEnv,Threads ,jclass, jmethodID, and jfieldID,UTF-8 and UTF-16 Strings,Exceptions,Native Libraries等等]

    JNI Tips In this document JavaVM and JNIEnv Threads jclass, jmethodID, and jfieldID Local and Global ...

  2. Android JNI总结

    @Dlive 0x01 JNI介绍 JNI是Java Native Interface的缩写,JNI不是Android专有的东西,它是从Java继承而来,但是在Android中,JNI的作用和重要性大 ...

  3. Java Native Interfce三在JNI中使用Java类的普通方法与变量

    本文是<The Java Native Interface Programmer's Guide and Specification>读书笔记 前面我们学习了如何在JNI中通过参数来使用J ...

  4. NDK开发—基础知识实战Demo

    简介 前面写了几篇NDK相关的文章: NDK开发-简介&环境搭建(Eclipse,Android Studio) NDK开发-Android Studio+gradle-experimenta ...

  5. NDK开发-零散知识点整理

    JavaVM 标准Java平台下,每一个Process可以产生很多JavaVM对象,但在Android平台上,每一个Process只能产生一个Dalvik VM对象,也就是说在Android进程中是通 ...

  6. android 官方文档 JNI TIPS

    文章地址  http://developer.android.com/training/articles/perf-jni.html JNI Tips JNI is the Java Native I ...

  7. Android NDK几点回调方式

    一.NDK中获取android设备ID的方式 Java代码如下(获取设备ANDROID_ID): final String androidId = Secure.getString(context.g ...

  8. NDK-JNI实战教程(二) JNI官方中文资料

    声明 设计概述 JNI接口函数和指针 加载和链接本地方法 解析本地方法名 本地方法的参数 引用Java对象 全局和局部引用 实现局部引用 访问Java对象 访问基本类型数组 访问域和方法 报告编程错误 ...

  9. NDK开发之javaVM

    1.关于JNIEnv和JavaVM JNIEnv是一个与线程相关的变量,不同线程的JNIEnv彼此独立.JavaVM是虚拟机在JNI层的代表,在一个虚拟机进程中只有一个JavaVM,因此该进程的所有线 ...

随机推荐

  1. HDU 2476 区间DP String painter

    题解 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm ...

  2. STM32F407 I2C 个人笔记

    源代码;https://github.com/YuQiao0303/STM32F407-Examples/tree/master/24.IIC 概述 I2C (IIC, Inter-Integrate ...

  3. Python requests模块params、data、json的区别

    json和dict对比 json的key只能是字符串,python的dict可以是任何可hash对象(hashtable type): json的key可以是有序.重复的:dict的key不可以重复. ...

  4. Leetcode 329.矩阵中的最长递增路径

    矩阵中的最长递增路径 给定一个整数矩阵,找出最长递增路径的长度. 对于每个单元格,你可以往上,下,左,右四个方向移动. 你不能在对角线方向上移动或移动到边界外(即不允许环绕). 示例 1: 输入: n ...

  5. 2017年 湘潭邀请赛(湖南)or 江苏省赛

    这套题是叉姐出的,好难啊,先扫一遍好像没有会做的题了,仔细一想好像D最容易哎 Super Resolution Accepted : 112   Submit : 178 Time Limit : 1 ...

  6. 九度oj 题目1354:和为S的连续正数序列

    题目描述: 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100.但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数).没多久, ...

  7. 九度oj 题目1051:数字阶梯求和

    题目描述: 给定a和n,计算a+aa+aaa+a...a(n个a)的和. 输入: 测试数据有多组,输入a,n(1<=a<=9,1<=n<=100). 输出: 对于每组输入,请输 ...

  8. Spring-IOC源码解读1-整体设计

    1. SpringIOC提供了一个基本的javabean容器,通过IOC模式管理依赖关系,并通过依赖注入和AOP增强了为javabean这样的pojo对象赋予事务管理,生命周期管理等基本功能.2. S ...

  9. miller_rabin + pollard_rho模版

    #include<stdio.h> #include<stdlib.h> #include<time.h> #include<math.h> #incl ...

  10. 【HDOJ5979】Convex(三角函数)

    题意:n个点在一个半径为R的圆上,给出这n个点顺时针的夹角差值,求这n个点的凸包面积 n<=10,R<=10 思路:S=1/2*sinθ*a*b 角度转弧度再用sin C++有点小毛病,叫 ...