看不明白,不过帮楼主顶一下!
我也关注这个问题
学习ing。。

解决方案 »

  1.   

    import java.lang.reflect.*;class Ref{
      public static final String XYZ="I am XYZ";
      public static void main(String[] args) {
        try{
          Field f = Class.forName("Ref").getField("XYZ");
          String s = (String)f.get(Class.forName("Ref").newInstance());
          System.out.println(s);
        }catch(Exception e){e.printStackTrace();}
      }
    }
      

  2.   

    谢谢helpall不过因为类JRXlsExporterParameter没有不带参数的构造函数,因此无法使用Class.newInstance(),又因为该构造函数是protected的,因此无法在其他类中调用指定的Constructor创建实例
      

  3.   

    package myPackage;
    public class JRXlsExporterParameter
    {
    protected JRXlsExporterParameter(String name){
    //super(name);
    }
    public String toString(){
    return "fog628";
    }
    public static final JRXlsExporterParameter IS_ONE_PAGE_PER_SHEET = new JRXlsExporterParameter("Is One Page per Sheet");
    public static final JRXlsExporterParameter IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS = new JRXlsExporterParameter("Is Remove Empty Space Between Rows");
    public static final JRXlsExporterParameter IS_WHITE_PAGE_BACKGROUND = new JRXlsExporterParameter("Is White Page Background");
    public static final JRXlsExporterParameter IS_AUTO_DETECT_CELL_TYPE = new JRXlsExporterParameter("Is Auto Detect Cell Type");
    }
    这是楼主的原类:改了一点点东西
    1、package myPackage;  为了说明构造函数是protected
    2、没有extends  JRExporterParameter
    3、加了一个toString()用来打印=======================================================
    import java.lang.reflect.*;
    import myPackage.JRXlsExporterParameter;public class Ref{
    public static void main(String[] args) throws Exception{
         Class c = JRXlsExporterParameter.class;
         Field f = c.getDeclaredField("IS_ONE_PAGE_PER_SHEET");
             //调用静态的东西不用生成一个新的实例
         Object o = f.get(null);
         System.out.println(o);//结果为fog628
        }
    }
      

  4.   

    http://community.csdn.net/Expert/topic/3811/3811744.xml?temp=.3853571
      

  5.   

    感谢! helpall() fog628(风舞轻扬) bigc2000(公元2005年4月9日)