I was asked in an interview about which collection breaks the S.O.L.I.D principle??
Can anyone explain which one is it and how?
Java provides a generic collection called IdentityHashMap<K,V>
, which breaks Liskov substitution principle - the "L" in SOLID by intentionally violating Map<K,V>
's contract.
Here is a note from the documentation of the IdentityHashMap<K,V>
class:
This class is not a general-purpose Map implementation! While this class implements the Map interface, it intentionally violates Map's general contract, which mandates the use of the equals method when comparing objects. This class is designed for use only in the rare cases wherein reference-equality semantics are required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With