Add java17-features module: runnable demos and captured output for the ankurm.com java17-features article
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
/** Fails to compile on purpose: record fields are final. */
|
||||
public class RecordFieldMutation {
|
||||
record Point(int x, int y) { void move() { this.x = 10; } }
|
||||
public static void main(String[] args) { }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
/** Fails to compile on purpose: a class that is not in the permits list cannot extend a sealed type. */
|
||||
public class SealedViolation {
|
||||
sealed interface Shape permits Circle {}
|
||||
record Circle(double r) implements Shape {}
|
||||
record Triangle(double b, double h) implements Shape {}
|
||||
public static void main(String[] args) { }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/** Fails on 17 without --enable-preview: pattern matching for switch is only a preview feature in 17 (JEP 406). */
|
||||
public class SwitchPatternOn17 {
|
||||
static String f(Object o) { return switch (o) { case String s -> "string"; default -> "other"; }; }
|
||||
public static void main(String[] args) { System.out.println(f("x")); }
|
||||
}
|
||||
Reference in New Issue
Block a user