简体   繁体   中英

Queue interface in Java and default interface

I am reading about default interfaces in Java. I am say trying to implement a Queue interface but do not wish to write implementation of all the methods. I wonder how do I do that because the "Queue" and "Collections" interface do not have default methods in Java

One way is to extend an already implemented subclass and override methods of our choice.

For example, we can extend ArrayDeque and override peek() if we want to

class MyQueue<E> extends ArrayDeque<E> {
    @Override
    public E peek() {
        return null;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM