Pattern Matching for switch (Second Preview)

Remi Forax forax at univ-mlv.fr
Wed Sep 22 20:37:05 UTC 2021


And i think we should also fix the following

4. a case that mix constants and a type pattern (or a guard) of a supertype of the types of the constants should be allowed
   By example,
     case 3, Integer i -> 
   or
     case 4, Object o ->

5. add an partial order edge between a guarded pattern and a constant of a subtypes of the type of the guarded pattern
   This code currently compiles
    switch(value) {
      case Integer i && bar() -> {}
      case 3 -> {}
      case Integer i -> {}
    }

   but i think it should be written
    switch(value) {
      case 3 -> {}
      case Integer i && bar() -> {}
      case Integer i -> {}
    }

   so the code is easier to read. 

Rémi

----- Original Message -----
> From: "jan lahoda" <jan.lahoda at oracle.com>
> To: "amber-dev" <amber-dev at openjdk.java.net>
> Sent: Mercredi 22 Septembre 2021 18:11:13
> Subject: Pattern Matching for switch (Second Preview)

> Hi,
> 
> There is a new draft JEP for preview 2 of Pattern Matching for switch here:
> https://bugs.openjdk.java.net/browse/JDK-8273326
> 
> The exact changes that will be done under this round of preview are yet
> to be determined, but changes related to generics handling in pattern
> matching switches seem to be plausible.
> 
> Feedback is welcome!
> 
> Thanks,
>      Jan


More information about the amber-dev mailing list