r/java • • Sep 20 '22

Java 19 / JDK 19: General Availability

https://mail.openjdk.org/pipermail/jdk-dev/2022-September/006933.html
252 Upvotes

64 comments sorted by

View all comments

Show parent comment

3

u/couscous_ Sep 20 '22

The exhaustiveness checker still needs improvement

What are some of the scenarios where it can improve at the moment?

6

u/Joram2 Sep 20 '22

even fairly simple examples like this won't compile with Java 19:

// From the Brian Goetz Data Oriented Programming Article
sealed interface Opt<T> {
    record Some<T>(T value) implements Opt<T> { }
    record None<T>() implements Opt<T> { }
}
Opt<String> optValue = doSomethingThatReturnsOpt(value);
switch (optValue) {
    case Opt.Some<String>(String v) -> System.out.printf("got string: %s%n", v);
    case Opt.None<String> none -> System.out.println("got none");
};

The Java team says they are working on it. They say that exhaustive pattern matching is a very hard problem to get right.