permits implementieren und default entfernen #346

Open
opened 2024-09-04 12:31:12 +00:00 by pl · 0 comments
Owner

Bsp.:
sealed interface List permits LinkedElem, Elem {}

public record LinkedElem(T a, List l) implements List {}
public record Elem(T a) implements List {}

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));
**//**default -> null;
};
}
}

Bsp.: 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)); **//**default -> null; }; } }
dholle was assigned by pl 2024-09-04 12:31:12 +00:00
RubenKraft was assigned by pl 2024-09-04 12:31:12 +00:00
Sign in to join this conversation.
No Milestone
No project
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: JavaTX/JavaCompilerCore#346
No description provided.