Home  >  Article  >  Java  >  How to operate default interface in java

How to operate default interface in java

WBOY
WBOYforward
2023-05-10 12:10:061427browse

Explanation

1. The default keyword provides the default implementation for the abstract method defined by the interface.

2. The new feature of the default keyword can easily expand the previous interface, but there is no need to make any changes to the implementation class of this interface.

Examples

// 定义一个公式接口
interface Formula {
    // 计算
    double calculate(int a);
 
    // 求平方根
    default double sqrt(int a) {
        return Math.sqrt(a);
    }
}

What collection classes are there in Java

Collections in Java are mainly divided into four categories:

1, List List: ordered, repeatable;

2, Queue queue: ordered, repeatable;

3, Set collection: non-repeatable;

4, Map mapping: unordered, unique keys, non-unique values.

The above is the detailed content of How to operate default interface in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete