8 basic data types (byte, short, char, int, long, float, double, boolean) compare whether their values are equal.
For reference data types, the comparison is whether their addresses in the heap memory are equal. Every time an object of reference type is new, the heap memory space will be reallocated, and the == comparison will return false.
Here you can see that the address values of the two are different
identityHashCode(), whether rewritten or not, can see the address value
So the output s1 != s2
Compare using equals
The equals method is a method of the Object class, and all classes in Java inherit from the Object superclass.
The source code of the equals method of the JDK1.8 Object class is as follows, that is, the return result depends on the use == judgment result of the two objects.