908aca29ca
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
32 lines
848 B
Java
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;
|
|
};
|
|
}
|
|
|
|
}
|