equals()とhashCode()をオーバーライドしないと何が起きるか
https://qiita.com/S_kamon/items/e80c066455beca2e344e?utm_campaign=popular_items&utm_medium=feed&utm_source=popular_items
equals()とhashCode()をオーバーライドしないと何が起きるか
https://qiita.com/S_kamon/items/e80c066455beca2e344e?utm_campaign=popular_items&utm_medium=feed&utm_source=popular_items
Wer in Java eigene Klassen schreibt, kommt früher oder später an den Punkt, an dem `equals()`, `hashCode()` und `toString()` relevant werden. Diese drei Methoden stammen alle aus der Klasse `Object`, also der obersten Basisklasse in Java. Deshalb hat jede Klasse sie automatisch - aber oft reicht d
https://magicmarcy.de/equals-hashcode-und-tostring-richtig-implementieren
#equals #hashCode #toString #Basisklasse #Grundlagen #Object #vergleichen #Collections #Hash-basiert
Wer in Java eigene Klassen schreibt, kommt früher oder später an den Punkt, an dem equals(), hashCode() und toString() relevant werden. Diese drei Methoden stammen alle aus der Klasse Object, also der obersten Basisklasse in Java. Deshalb hat jede Klasse sie automatisch – aber oft reicht die Standard-Implementierung nicht aus. Besonders wenn du Objekte miteinander vergleichen oder in Collections wie HashSet oder HashMap speichern möchtest, wird es wichtig, diese Methoden richtig zu überschreiben.
🤦♂️ Why String.GetHashCode in .NET Drives You Crazy 🤪
➡ I needed to keep track of transactions between tool runs. I saved a hashcode of a transaction in DB.
➡ Tool would generate a new hash-code and compare it to the one already saved in DB.
➡ At same run, it is fine. But, after re-running, generated hashcode -of the same transaction- is not same as one in DB.
➡ Read this article to know how to overcome this.
📖 https://developmentsimplyput.com/post/when-string-gethashcode-in-net-c-drives-you-crazy
📭 http://developmentsimplyput.com/subscribe
#dotnet #softwaredesign #softwarearchitecture #bestpractice #string #hashcode
🤦♂️ Why String.GetHashCode in .NET Drives You Crazy 🤪
➡ I needed to keep track of transactions between tool runs. I saved a hashcode of a transaction in DB.
➡ Tool would generate a new hash-code and compare it to the one already saved in DB.
➡ At same run, it is fine. But, after re-running, generated hashcode -of the same transaction- is not same as one in DB.
➡ Read this article to know how to overcome this.
📖 https://developmentsimplyput.com/post/when-string-gethashcode-in-net-c-drives-you-crazy