Last active
January 22, 2022 15:51
-
-
Save TGITS/78f4b9e3508aea23bd2805e450ec7fa1 to your computer and use it in GitHub Desktop.
Exemple de fonctionnement des méthodes equals et hashCode des records
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A exécuter sous JShell : /open RecordExampleScript_2.java | |
public record House(String name, String seat, String sigil, String familyWords) { | |
} | |
House house1 = new House("Stark", "Winterfell", "A Gray Direwolf", "Winter is coming"); | |
House house2 = new House("Stark", "Winterfell", "A Gray Direwolf", "Winter is coming"); | |
house1 == house2; // false - 2 références distinctes | |
house1.equals(house2); // true - comparaison basée sur le contenu | |
house1.hashCode() == house2.hashCode(); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment