As e.g. in https://github.com/s-ludwig/taggedalgebraic:
final switch (taggedAny.kind) {
case Tagged.Kind.i:
// It's "int i"
break;
case Tagged.Kind.str:
// It's "string str"
break;
case Tagged.Kind.foo:
// It's "Foo foo"
break;
}
this has the advantage over visit that the compiler can enforce that all types are covered.
Comment #1 by robert.schadek — 2024-12-01T16:28:51Z