OnJava8-Examples/collections/CompactConstructor.java

17 lines
459 B
Java
Raw Permalink Normal View History

2021-09-20 17:33:35 -06:00
// collections/CompactConstructor.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {NewFeature} Since JDK 16
record Point(int x, int y) {
void assertPositive(int val) {
if(val < 0)
throw new IllegalArgumentException("negative");
}
Point { // Compact: No parameter list
assertPositive(x);
assertPositive(y);
}
}