When to use: Java 8+ interface default method, vs. abstract method

后端 未结 15 1766
闹比i
闹比i 2020-11-22 07:01

Java 8 allows for default implementation of methods in interfaces called Default Methods.

I am confused between when would I use that sort of interface default

15条回答
  •  盖世英雄少女心
    2020-11-22 07:34

    Remi Forax rule is You don't design with Abstract classes. You design your app with interfaces. Watever is the version of Java, whatever is the language. It is backed by the Interface segregation principle in SOLID principles.

    You can later use Abstract classes to factorize code. Now with Java 8 you can do it directly in the interface. This is a facility, not more.

提交回复
热议问题