One 、 Comparison of objects
Before, if it was a comparison of two values “==”, If it's a string comparison, it's usually used “equals()" Method , The method is String Class itself , How can we compare the objects of our custom class , If you use “==” Comparison compares the address information of two objects , But we normally think that all attribute values of two objects are equal, and two objects are equal .
DEMO: Compare the objects of a custom class
The above can realize object comparison , But it's implemented in the main method , General requirements The logical business code should be avoided as far as possible , The main method is a client , It's better to leave the process of comparison to Dept Class to complete .
DEMO: stay Dept Methods are defined in to realize the comparison of objects