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

后端 未结 15 1786
闹比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

    There are a few technical differences. Abstract classes can still do more in comparison to Java 8 interfaces:

    1. Abstract class can have a constructor.
    2. Abstract classes are more structured and can hold a state.

    Conceptually, main purpose of defender methods is a backward compatibility after introduction of new features (as lambda-functions) in Java 8.

提交回复
热议问题