public String getName() {
return new String("foobar");
}
if(getName() != "foobar2") {
//Never gets executed, it should, wtf!.
}
if(!getName().equals("foobar2")) {
//This works how it should.
}
ええ、私の質問は簡単です.. なぜaka ( )!=
と同じように動作しないのですか?!equals()
not Equals
どちらかが失敗する論理的な理由はわかりません。どちらも私の心の中ではまったく同じコードです、WTH。
Java オペレーターを見る http://download.oracle.com/javase/tutorial/java/nutsandbolts/operators.html
平等がはっきりわかる ==
!=
確かに、私は通常!=
、数値に対してのみ使用します..しかし、私の心はさまよい始めました.なぜそれが機能しないのString
ですか?
編集: これは実際の問題に似たものです..
for (ClassGen cg : client.getClasses().values()) {
final ConstantPoolGen cp = cg.getConstantPool();
if(cp.lookupInteger(0x11223344) != -1) {
for (Method m : cg.getMethods()) {
System.out.println("lots of class spam");
if(m.getName() != "<init>") continue;
System.out.println("NEVER GETS HERE, 100% SURE IT HAS CONSTRUCTOR LOL");
}
}
}