News for hackers. Stuff that matters.
Re:Java 20 / JDK 20: General Availability by kaba0 on Wednesday March 22, 2023 @03:09AM (#35257781)
This is not really pattern matching, that’s just a regular old if-else.

https://news.ycombinator.com/item?id=35133670

This is absolutely possible in Java and the only less-than-ideal part is the generic type having to be specified in the None case (but a trivial method fixes that as well)

This can be used just like rust and similar languages:

  switch (option) {
    case Some(var x) -> println(x);
    case None -> // TODO
  }
Hell, you can just further pattern match inside Some, like `Some(Point(var x, var y))`

There are no comments on this comment yet.