、、、およびオブジェクトでは機能しないため<
、自分>
で試していないようです。<=
>=
ただし、==
左右のオペランドを比較します。それらが同じバイナリである場合、それは真になります。オブジェクトの場合、でポインタを比較します。つまり、これは、オブジェクトがメモリ内のまったく同じオブジェクトの左右にある場合にのみtrueになることを意味します。
compareToやequalsなどの他のメソッドは、メモリ内の異なるオブジェクトと比較するカスタムメソッドを提供するために作成されますが、これらは互いに等しい場合があります(つまり、データは同じです)。
文字列の場合、例:
String str0 = new String("foo");
String str1 = new String("foo");
// A human being would say that the two strings are equal, which is true
// But it are TWO different objects in memory. So, using == will result
// in false
System.out.println(str0 == str1); // false
// But if we want to check the content of the string, we can use the equals method,
// because that method compares character by character of the two objects
String.out.println(str0.equals(str1)); // true
String.out.println(str1.equals(str0)); // true