直接写吧:
String method=FieldCommon.SEX;
String method=FieldCommon.SEX;
解决方案 »
- 急急急!!!请求高手!java长方形图形重叠!!跪求帮助!!没时间了!拜托大家!
- Java, MySQL 大批量数据输入的问题
- Eclipse单步调试为什么进不了调用类的构造函数?
- 关于把java源码编译成可执行程序问题高手进!
- jsp中include指令怎样使用
- FileOutputStream自动覆盖文件的问题
- 高手指教:在JBuilder里连接数据库出现的问题如何解决?
- 50分请教问题----报错信息如下:ClassCastException: com.sun.mail.pop3.POP3Store
- 关于类的方法的讨论?
- ResultSet浏览只能用next()! 我错在哪里?
- 请问大家,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);