if(field.getType() == String.class){ } 为什么必须要有这句?private static void changeStringValue(Object obj) throws Exception {// TODO Auto-generated method stubField[] fields = obj.getClass().getFields();for (Field field :fields) {if(field.g

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 13:11:27
if(field.getType()==String.class){}为什么必须要有这句?privatestaticvoidchangeStringValue(Objectobj)throwsExce

if(field.getType() == String.class){ } 为什么必须要有这句?private static void changeStringValue(Object obj) throws Exception {// TODO Auto-generated method stubField[] fields = obj.getClass().getFields();for (Field field :fields) {if(field.g
if(field.getType() == String.class){ } 为什么必须要有这句?
private static void changeStringValue(Object obj) throws Exception {
// TODO Auto-generated method stub
Field[] fields = obj.getClass().getFields();
for (Field field :fields) {
if(field.getType() == String.class){
String oldValue = (String) field.get(obj);
String newValue = oldValue.replace('b','a');
field.set(obj,newValue);
}
}
}

if(field.getType() == String.class){ } 为什么必须要有这句?private static void changeStringValue(Object obj) throws Exception {// TODO Auto-generated method stubField[] fields = obj.getClass().getFields();for (Field field :fields) {if(field.g
其实就是判断一下一个类中的属性的类型是不是String