package blatt14; public class List { private final T info; private final List next; public List(T info, List next) { this.info = info; this.next = next; } public static List filter(List node, Predicate pred) { if (node == null) return null; List rest = filter(node.next, pred); if (pred.applies(node.info) == true) { return new List<>(node.info, rest); } else { return rest; } } public static List filter2(List node, Predicate pred) { List ret = null; while (node != null) { if (pred.applies(node.info)) { ret = new List(node.info, ret); } node = node.next; } return ret; } } interface Predicate { boolean applies(T toWhat); }