Skip to content

Instantly share code, notes, and snippets.

@Sedose
Last active September 4, 2024 13:29
Show Gist options
  • Save Sedose/d0c1051cb71f915ac277bbd1f5f7b3a2 to your computer and use it in GitHub Desktop.
Save Sedose/d0c1051cb71f915ac277bbd1f5f7b3a2 to your computer and use it in GitHub Desktop.
Java record instances are equal by the record members
import java.util.Objects;
private record AddressIdentity(
String city,
String streetName,
String streetNumber
) {}
void main() {
var first = new AddressIdentity("Kyiv", "Babusia", "12345");
var second = new AddressIdentity("Kyiv", "Babusia", "12345");
System.out.println(STR."The record instances must be equal. Expected true. Actual: \{Objects.equals(first, second)}");
}
@Sedose
Copy link
Author

Sedose commented Sep 4, 2024

To run open terminal and run java --enable-preview --source 22 Main.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment