java8-新特性default
生活随笔
收集整理的這篇文章主要介紹了
java8-新特性default
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
java8中提供了新的關(guān)鍵字default 用于在接口中直接指定默認(rèn)方法
public interface Collection<E> extends Iterable<E> {? ?default boolean removeIf(Predicate<? super E> filter) {Objects.requireNonNull(filter);boolean removed = false;final Iterator<E> each = iterator();while (each.hasNext()) {if (filter.test(each.next())) {each.remove();removed = true;}}return removed;} ... }但是當(dāng)一個(gè)類繼承多個(gè)接口 而這些接口都提供了默認(rèn)實(shí)現(xiàn)的時(shí)候 必須進(jìn)行重寫
interface DefInterface1 {default void hello(String ss) {}; }interface DefInterface2 {//default void hello(String ss) {}; }public class impl implements DefInterface1,DefInterface2 {// public void hello(String ss) { // // TODO Auto-generated method stub // System.out.println("OL"); // }public static void main(String[] args) {new impl().hello(new String("aa"));}}?
轉(zhuǎn)載于:https://my.oschina.net/dajianguo/blog/1502935
總結(jié)
以上是生活随笔為你收集整理的java8-新特性default的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 理解 Python 中的多线程
- 下一篇: 【阿里云大学课程】前端必知——HTML5