28 lines
564 B
Plaintext
28 lines
564 B
Plaintext
|
import java.lang.Object;
|
||
|
import java.lang.String;
|
||
|
|
||
|
|
||
|
|
||
|
sealed interface List permits LinkedElem {}
|
||
|
|
||
|
|
||
|
public record LinkedElem<T>(T a,List l) implements List{} //Implementiert List und wird auch permittet
|
||
|
public record Elem<T>(T c) implements List{} //Implementiert List, wird aber nicht permittet
|
||
|
|
||
|
public class SwitchCaseHeritageDetection {
|
||
|
public main(o) {
|
||
|
return switch(o) {
|
||
|
case LinkedElem(a, Elem(e)) -> a ;
|
||
|
case LinkedElem(a, LinkedElem(e, Elem(f))) -> e;
|
||
|
default -> null;
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|