String型とObject型の比較
String型の値とObject型の値をequalsメソッドで比較します。
falseになったような気がしましたが、検証してみるとtrueが返ります。

以下、サンプルです。

public class Test {
    public static void main(String[] args) {
        Object obj = "0";
        String str = new String("0");
        if(obj.equals(str)){
            System.out.println("true");
        }else{
            System.out.println("false");
        }
    }
}
実行結果は以下のようになります。

true

Back to top

Information