Skip to content

Instantly share code, notes, and snippets.

@sebastienblanc
Last active September 1, 2020 15:34
Show Gist options
  • Save sebastienblanc/964d1235ce55880f12fe75445c5e55b9 to your computer and use it in GitHub Desktop.
Save sebastienblanc/964d1235ce55880f12fe75445c5e55b9 to your computer and use it in GitHub Desktop.
//usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 15
//JAVAC_OPTIONS --enable-preview -source 15
//JAVA_OPTIONS --enable-preview
record Point(int x, int y) {}
sealed interface Shape
permits Circle, Rectangle {
}
record Circle(Point center, int radius) implements Shape { }
record Rectangle(Point lowerLeft, Point upperRight) implements Shape { }
//record Pet(String name) implements Shape {}
var shape = new Circle(new Point(2,3), 30);
if (shape instanceof Circle c) {
// compiler has already cast shape to Circle for us, and bound it to c
System.out.printf("Circle of radius %d%n", c.radius());
}
//System.out.println(shape);
/exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment