News for hackers. Stuff that matters.
Re:Java 21: What’s New? by kaba0 on Thursday August 10, 2023 @04:07AM (#37073364)
There is subtyping.

A more practical (though not necessarily realistic) example might be:

  sealed interface List<T> permits Cons<T>, None<T> {
    record Cons<T>(T head, List<T> tail) {}
    record None<T>() {}
  }


  // some function only wanting the  first elem of a list
  switch (List<T> list) {
    case Cons<>(T head, var tail) -> // do something
    default -> {}
  }
If you have used Haskell or similarly strongly typed FP language, you can see how great pattern matching can be.

There are no comments on this comment yet.