我已經測試過幾種不同的方法。我比較s
的字符串與日誌文件中顯示的字符串完全相同。撇號是爲了確保沒有空格。任何人都知道發生了什麼事?Java Method.getName()與字符串不匹配
import java.lang.reflect.Method;
import android.util.Log;
public class Button {
public Button() {
for(Method m1:MyOtherClass.class.getMethods()) {
String s = m1.getName();
if(s == "Update") {
Log.i("result","true");
}
Log.i("test", "'" + s + "'");
}
}
}
啊,我不知道這個。謝謝。 – 2012-07-19 01:08:13
別擔心。大家都是這樣比較字符串:) – Pshemo 2012-07-19 01:11:43