直接写吧:
String method=FieldCommon.SEX;
String method=FieldCommon.SEX;
解决方案 »
- AXIS2+SSL 的问题,请高手帮忙!
- (新手求助)程序,线程,进程,多线程,谁帮我解释一下
- java如何获取文件(一般是可执行的)的版本号
- 某个大公司的面试题目?
- 关于JTree的问题
- 静态方法在继承中的情况!
- 两个线程调用同一个static方法,彼此会不会影响,全局变量不用说了,那局部变量呢
- 送分啊
- 请问在JLIST的渲染器单元中可不以监听鼠标事件(不好意思,最多只能给100分)
- 如何让批处理文件执行完毕后窗口不关闭,批处理文件直接点击执行
- 请问大家,java中是怎么获得网卡地址的阿?在线等
- *********Jtable的某一格被选中后,背景色会变,请问这个怎么做?************
this.SEX = sex;
}
public String getSex() {
return SEX;
}
Field f=Class.forName(classname).getField(para);
String method=(String)f.get(f);
FieldCommon fieldCommon = new FieldCommon();
String method = fieldCommon.SEX;
String para = "getStr";
try{
Method f = Class.forName(classname).getMethod("getStr",null);
}catch(Exception ex){
ex.printStackTrace();
}
public String getSex()
{
return SEX;
}
method是其他类类的成员函数,那么:
public String getSex()
{
return FieldCommon.SEX;
}方法二:
String method=FieldCommon.SEX;static 数据的调用方法:类名.数据成员 !static方法也一样!
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);
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);
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);