Totality over generics

Per Minborg minborg at speedment.com
Fri Sep 24 16:19:40 UTC 2021


Hi,

What if we could do something like this in some distant future:

     <T extends Integer | String> int eval(T t) {
         return switch (t) {
             case Integer i -> i;
             case String s -> Integer.parseInt(s);
             case null -> 0;
             // Totality
         };
     }


Already today , an equivalent second layer of sealed wrapper classes 
could achieve the same goal but with much more ceremony. Of course, 
there are also overloads but how cool is that?

Best, Per Minborg



More information about the amber-dev mailing list