<div dir="ltr"><div class="gmail_default" style="font-size:small">Thank you. Yes, that is the best we can do if we want to know about the changes, listing the cases we are aware of, using a concise syntax. With leftovers it would be possible listing multiple type patterns under a single label. Currently it is possible only using multiple case entries. I could imagine a syntax like this: case (BadCase, ReallyBadCase, AwfulCase) i -> .... but here the i should be an Object type - or the lowest common type. (In spite of that it isn't the same as "case Object i ->")</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">BTW, playing with the syntax I realised Java 18 accepts both the "default" and "case default" labels (using legacy and arrow syntax as well). Java 8 accepts only "default". (In the specs I found only this format.)</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 20 Jun 2022 at 15:45, Brian Goetz <<a href="mailto:brian.goetz@oracle.com" target="_blank">brian.goetz@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

  
  <div>
    <br>
    <br>
    <blockquote type="cite">
      <div dir="ltr">
        <div dir="ltr">
          <div class="gmail_default" style="font-size:small">
            <div dir="ltr">
              <div class="gmail_default">Looking at your example, when
                an additional sealed subclass will be added. Yes, it
                would be very useful to warn the programmers. But
                imagine a situation when the totality isn't intended, so
                the programmer wants a side effect only in a few cases.
                She will be forced to add an empty default clause. And
                later, when a new sealed subclass will be added, there
                won't be any alert, as the switch is already total,
                forever. Surely, it helped a little bit to increase the
                safety initially (the programmer was forced to think
                about the missing cases), but with a lot of empty
                default clauses this safety will be partial.</div>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    Well, it depends how many cases your sealed type has.  If it has
    few, then you can totalize by naming all the cases.  Now, right now
    that is a little cumbersome, but in the future you will probably be
    able to do:<br>
    <br>
        switch (x) { <br>
            case GoodCase g: ...<br>
            case AlsoGoodCase g: ...<br>
            case BadCase _, ReallyBadCase _, AwfulCase _: throw ...<br>
        }<br>
    <br>
    which, depending on how many permitted types there are, still
    preserves the "tell me when something changes" behavior.  (You can't
    do this now because you can't merge patterns with bindings, and you
    can't yet suppress a binding.  All in due time.)<br>
           <br>
    <blockquote type="cite">
      <div dir="ltr">
        <div dir="ltr">
          <div class="gmail_default" style="font-size:small">
            <div dir="ltr">BTW, Scala allows switch expressions without
              totality, only a warning is raised. This seems a
              safety risk to me, no idea why it was implemented this
              way.</div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    FWIW, Haskell also allows functions defined by case to be partial
    too.  <br>
    <br>
    <br>
  </div>

</blockquote></div>