Last active
September 1, 2020 15:34
-
-
Save sebastienblanc/964d1235ce55880f12fe75445c5e55b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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