Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b7N4ZDbUtA3ofqAqRV
25 lines
854 B
Java
25 lines
854 B
Java
// JEP 401: Value Objects (Preview). Run with --enable-preview on JDK 28.
|
|
value record Money(String currency, long paise) {}
|
|
|
|
record Ordinary(String currency, long paise) {}
|
|
|
|
void main() {
|
|
Money a = new Money("INR", 500);
|
|
Money b = new Money("INR", 500);
|
|
IO.println("value record a == b : " + (a == b));
|
|
IO.println("ordinary record a == b: " + (new Ordinary("INR", 500) == new Ordinary("INR", 500)));
|
|
IO.println("Money has identity : " + Objects.hasIdentity(a));
|
|
|
|
Integer x = 1996, y = 1996;
|
|
IO.println("Integer 1996 == 1996 : " + (x == y));
|
|
|
|
Object o = x; // hide the static type from javac
|
|
try {
|
|
synchronized (o) {
|
|
IO.println("locked an Integer");
|
|
}
|
|
} catch (IdentityException e) {
|
|
IO.println(e.getClass().getSimpleName() + ": " + e.getMessage());
|
|
}
|
|
}
|