-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathGuardedPatterns.java
More file actions
executable file
·24 lines (22 loc) · 617 Bytes
/
Copy pathGuardedPatterns.java
File metadata and controls
executable file
·24 lines (22 loc) · 617 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 25+
/// Proof: guarded-patterns
/// Source: content/language/guarded-patterns.yaml
sealed interface Shape permits Circle, Other {}
record Circle(double radius) implements Shape {}
record Other() implements Shape {}
String describe(Shape shape) {
return switch (shape) {
case Circle c
when c.radius() > 10
-> "large circle";
case Circle c
-> "small circle";
default -> "not a circle";
};
}
void main() {
describe(new Circle(5));
describe(new Circle(15));
describe(new Other());
}