Let's take a look at this Code:
Public class IntergerError {public static void main (String [] args) {// TODO Auto-generated method stubInteger num1 = new Integer (100); Integer num2 = new Integer (100 ); system. out. println (compare (num1, num2);} private static boolean compare (Integer num1, Integer num2) {boolean a = (num1 = num2 ); boolean B = (num1> num2); boolean c = (num1 <num2); return a | B | c ;}}
What is your answer, and the return value must be true? Haha, think about it again. The return value of this Code is false, which makes it hard to understand. Why? Since we use or, it is not big, small, or equal, it must be true. The above is also my idea. Later I found some information on the Internet and concluded that "=" is a relatively simple type value or whether the comparison object references the same object, as for "" and "", it is meaningless for objects. Therefore, it is best to use the equal () method or the de-object value to compare the object values. In fact, this issue has not caught much attention before. Today, we have encountered a disaster that is caused by poor foundation. Hope you can criticize and correct your experience.