直接写吧:
String method=FieldCommon.SEX;

解决方案 »

  1.   

    public void setSex(String sex) {
      this.SEX = sex;
    }
     
    public String getSex() {
      return SEX;
    }
      

  2.   

    刚才试了一下:String classname="FieldCommon";//
          Field f=Class.forName(classname).getField(para);
          String method=(String)f.get(f);
      

  3.   

    先生成一个FieldCommon的实例,然后定义你的method指向sex.
    FieldCommon fieldCommon = new FieldCommon();
    String method = fieldCommon.SEX;
      

  4.   

    String classname="TTT";//
        String para = "getStr";
        try{
          Method f = Class.forName(classname).getMethod("getStr",null);
        }catch(Exception ex){
          ex.printStackTrace();
        }
      

  5.   

    我也建议直接写:String method=FieldCommon.SEX;
      

  6.   

    To:  cxy550(小宇): 根本不需要先生成一个FieldCommon的实例,你没见那些数据都是static 的吗?方法一:method是FieldCommon类的成员函数,那么:
            
            public String getSex() 
            {
              return SEX;
            }
            method是其他类类的成员函数,那么:
            public String getSex() 
            {
              return FieldCommon.SEX;
            }方法二:
            String method=FieldCommon.SEX;static 数据的调用方法:类名.数据成员 !static方法也一样! 
            
      

  7.   

    大家似乎理解错我的意思了.不过我找到解决的办法了.
    public static Object getCommonValue(String classname,String fieldname){
        try{
            Class c = Class.forName(classname);
            Field field = c.getField(fieldname);
            return field.get(fieldname);
            }catch(Exception e){e.printStackTrace();}
        return null;
      }  FieldClass Item=(FieldClass)getCommonValue("FieldCommon",fieldname);
      

  8.   

    大家似乎理解错我的意思了.不过我找到解决的办法了.
    public static Object getCommonValue(String classname,String fieldname){
        try{
            Class c = Class.forName(classname);
            Field field = c.getField(fieldname);
            return field.get(fieldname);
            }catch(Exception e){e.printStackTrace();}
        return null;
      }  FieldClass Item=(FieldClass)getCommonValue("FieldCommon",fieldname);
      

  9.   

    大家似乎理解错我的意思了.不过我找到解决的办法了.
    public static Object getCommonValue(String classname,String fieldname){
        try{
            Class c = Class.forName(classname);
            Field field = c.getField(fieldname);
            return field.get(fieldname);
            }catch(Exception e){e.printStackTrace();}
        return null;
      }  FieldClass Item=(FieldClass)getCommonValue("FieldCommon",fieldname);
      

  10.   

    同意: geyf(其实我也不会) 说法