jdk-24/test/langtools/tools/javac/patterns/SimpleAndGuardPattern.java
Jan Lahoda 908aca29ca 8262891: Compiler implementation for Pattern Matching for switch (Preview)
Co-authored-by: Brian Goetz <briangoetz@openjdk.org>
Co-authored-by: Mandy Chung <mchung@openjdk.org>
Co-authored-by: Jan Lahoda <jlahoda@openjdk.org>
Reviewed-by: mcimadamore, forax, godin, psandoz, mchung
2021-06-07 07:01:30 +00:00

32 lines
848 B
Java

/**
* @test
* @compile --enable-preview -source ${jdk.version} -doe SimpleAndGuardPattern.java
* @run main/othervm --enable-preview SimpleAndGuardPattern
*/
import java.util.List;
import java.util.Objects;
public class SimpleAndGuardPattern {
public static void main(String... args) throws Throwable {
if (!Objects.equals(4, simple("test"))) {
throw new IllegalStateException();
}
if (!Objects.equals(4, simple("TEST"))) {
throw new IllegalStateException();
}
if (!Objects.equals(-1, simple("other"))) {
throw new IllegalStateException();
}
}
private static int simple(Object o) throws Throwable {
return switch (o) {
case String s && s.equalsIgnoreCase("test") -> s.length();
default -> -1;
};
}
}