JavaCompilerCore/resources/bytecode/javFiles/SwitchAppend.jav
Daniel Holle b7979ac7e7
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 7m41s
Fix tests
2024-09-26 11:31:24 +02:00

17 lines
589 B
Java

sealed interface List<T> permits LinkedElem, Elem {}
public record LinkedElem<T>(T a, List<T> l) implements List<T> {}
public record Elem<T>(T a) implements List<T> {}
public class SwitchAppend {
public append(l1, l2) {
return switch(l1) {
case LinkedElem(a, Elem(e)) -> new LinkedElem<>(a, new LinkedElem<>(e, l2));
case LinkedElem(a, r) -> new LinkedElem<>(a, append(r, l2));
//Alternativ:
//case LinkedElem(a, LinkedElem(e, r)) -> new LinkedElem<>(a, append(new LinkedElem(e, r), l2));
//default -> null;
};
}
}