equals 和等号,哪个更好怎么解释 为什么用equals比较好?
public class ReflectChangeStringDemo {
public static void main(String[] args) throws IllegalArgumentException, Exception {
ReflectPiontDemo rpd=new ReflectPiontDemo();
Field [] fields=rpd.getClass().getFields();
for(Field field:fields){
if(field.getType()==String.class){
String oldValue=(String) field.get(rpd);
String newValue=oldValue.replace('b', 'a');
field.set(rpd, newValue);
System.out.println(newValue);
}
}
}
}
public class ReflectPiontDemo {
public int str=1;
public String str1="sound";
public String str2="break";
public String str3="boll";
@Override
public String toString() {
// TODO Auto-generated method stub
return "str1"+str1+"str2"+str2+"str3"+str3;
}
}
|