On 4/18/21 9:51 AM, Peter Levart wrote:
public interface Collection<E> .... {
        default Collection<E> reversed() { return this; }
        default void addFirst(E e) { throw new UnsupportedOperationException(); }         default void addLast(E e) { throw new UnsupportedOperationException(); }


For unordered collections this could as well be:


        default void addFirst(E e) { return add(e); }
        default void addLast(E e) { return add(e); }


As the iteration of such modified unordered collection would not guarantee any order. SortedSet would of course override them with throwing methods.


default E getFirst() { return iterator().next(); }
        default E getLast() { return iterator().next(); }
        default E removeFirst() { var i = iterator(); i.next(); i.remove(); }         default E removeLast() { var i = iterator(); i.next(); i.remove(); } }

Reply via email to