zoukankan      html  css  js  c++  java
  • jclass和jobject的迷惑

    [译]jclassjobject  

    2012-09-18 15:02:58|  分类: Android |字号 订阅

     
    jclassjobject的迷惑
    第一次使用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.
  • 相关阅读:
    [网络流24题]飞行员配对方案问题
    bzoj 1571: [Usaco2009 Open]滑雪课
    bzoj 1001: [BeiJing2006]狼抓兔子
    bzoj 1711: [Usaco2007 Open]Dining吃饭
    bzoj 3379: [Usaco2004 Open]Turning in Homework 交作业
    bzoj 1412: [ZJOI2009]狼和羊的故事
    luogu P1345 [USACO5.4]奶牛的电信Telecowmunication
    hdu1512 Monkey King
    [BZOJ2006][NOI2010]超级钢琴(ST表+堆)
    [BZOJ4824][CQOI2017]老C的键盘(树形DP)
  • 原文地址:https://www.cnblogs.com/jeanschen/p/3318683.html
Copyright © 2011-2022 走看看