mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-24 08:09:22 +07:00
28 lines
812 B
Java
28 lines
812 B
Java
// "Remove guard expression" "true-preview"
|
|
import org.jetbrains.annotations.*;
|
|
|
|
import java.math.*;
|
|
|
|
public class Foo {
|
|
|
|
record Price(BigDecimal value) {
|
|
}
|
|
|
|
@Nullable
|
|
public Price price;
|
|
|
|
public String test() {
|
|
return switch (price) {
|
|
case Price p -> switch (p.value().multiply(BigDecimal.valueOf(100)).intValue()) {
|
|
case int i when i < 0 -> throw new IllegalStateException("Price is negative: " + p);
|
|
case 0 -> "free";
|
|
case 1, 2, 3, 4, 5, 6, 7, 8, 9 -> "cheap";
|
|
case int i when i < 100_00 -> "regular";
|
|
case int i when i < 1000_00 -> "expensive";
|
|
case int i -> "pricey";
|
|
case null -> throw new IllegalStateException("Price is out of range: " + p); //non-compilable, only for tests
|
|
};
|
|
case null -> "priceless";
|
|
};
|
|
}
|
|
} |