简体   繁体   中英

Is it compulsory to override equals() and hashCode() methods for final classes

Is it compulsory to override the methods equals() and hashCode() for final classes?

Note : as all Wrapper classes are final and immutable and overrides the equals and hashCode methods.

Thanks in advance

is it compulsary to override equals and hashCode methods for classes which are defined as final?

Define a class as final and overriding equals() and hashCode() are two different things.

Final is there to restrict a class not to be sub classed. And, equals() is there to check the equality of the instances of a class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM