就是这样的,
得到他的值用用Fields的get方法。用法请看文档

解决方案 »

  1.   

    可以把你的常量string全保存在一个vector/arraylist中嘛
    这样不管你怎么改,只要能取得那个vector/arraylist,就能打印出全部的常量拉
      

  2.   

    可以判断fields的类型,如果为String就取出
      

  3.   

    使用Field的方法不就可以了.参见JDK文档中的声明:public Object get(Object obj)
               throws IllegalArgumentException,
                      IllegalAccessExceptionReturns the value of the field represented by this Field, on the specified object. The value is automatically wrapped in an object if it has a primitive type. 
    The underlying field's value is obtained as follows: If the underlying field is a static field, the obj argument is ignored; it may be null. Otherwise, the underlying field is an instance field. If the specified obj argument is null, the method throws a NullPointerException. If the specified object is not an instance of the class or interface declaring the underlying field, the method throws an IllegalArgumentException. If this Field object enforces Java language access control, and the underlying field is inaccessible, the method throws an IllegalAccessException. If the underlying field is static, the class that declared the field is initialized if it has not already been initialized. Otherwise, the value is retrieved from the underlying instance or static field. If the field has a primitive type, the value is wrapped in an object before being returned, otherwise it is returned as is. If the field is hidden in the type of obj, the field's value is obtained according to the preceding rules. 
    Parameters:
    obj - object from which the represented field's value is to be extracted 
    Returns:
    the value of the represented field in object obj; primitive values are wrapped in an appropriate object before being returned 
    Throws: 
    IllegalAccessException - if the underlying field is inaccessible. 
    IllegalArgumentException - if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof). 
    NullPointerException - if the specified object is null and the field is an instance field. 
    ExceptionInInitializerError - if the initialization provoked by this method fails.
      

  4.   


    String a=fields[1].getName()
    String b=fields[0].getName()
      

  5.   

    我写了一个很简单的例子,你自己参照做就可以进行扩展了。
    ---------------------------------------------------
    测试用的类:
    class rclass
    {
    public static String fld1="zosatapo";
    public static String fld2="reic";
    public String fld3="yang";
    }
    -------------------------------------------------
    简单的测试程序:
    import java.lang.*;
    import java.lang.reflect.*;
    class rtest
    {
    public static void main(String []argv)
    {
    Class cls=rclass.class;
    Field flds[]=cls.getFields();
    for(int i=0;i<flds.length;i++)
    {
    int modifiers=flds[i].getModifiers();
    //Class type=flds[i].getType();
    //Fixed me!Here we assume that the type of all  
                      //fileds is String

    if(Modifier.isStatic(modifiers))
    {
    try
    {
    System.out.println(flds[i].getName()+"--->"+flds[i].get(null));
    }
    catch(IllegalAccessException e){}
    }
    }
    }
    }主要的注意点就是Field#get(Object obj)方法。由于我们的 field是类变量所以我只是简单的传递null作为参数的,如果是实例变量的话,你就要传递实例引用。
      

  6.   

    这些知识都是我们进行JNI编程必须要知道的。
      

  7.   

    主要的注意点就是Field#get(Object obj)方法。由于我们的 field是类变量所以我只是简单的传递null作为参数的,如果是实例变量的话,你就要传递实例引用。1.为什么要传递null?类变量?2.如果是实例变量的话,你就要传递实例引用。“实例引用”是什么意思?
      

  8.   

    to qiyao(qi)getName()只能得到Field's Name
      

  9.   

    1.为什么要传递null?类变量?
      类变量就是把类当成变量来使用! :)2.如果是实例变量的话,你就要传递实例引用。“实例引用”是什么意思?
      实例引用就是把类实例化来使用! :)
      

  10.   

    phoenix_zd(天马行空)类变量就是把类当成变量来使用! :)我的理解是类是抽象的所以要传null实例引用就是把类实例化来使用! :)new 一个实例么,我用过了,不好用,我用的是get(new 类名())
    不知道对不对?