当前位置:网站首页>Why are there "two abstract methods" in the functional interface comparator?
Why are there "two abstract methods" in the functional interface comparator?
2022-07-24 13:34:00 【pospre】
In these two days, I found that Comparator There is “ Two abstract methods ”, namely compare and equals. This makes me very confused , Isn't a functional interface only an abstract method ?( The specific methods 、default Methods are not included )

Until we see @FunctionalInterface Of JDK Documentation Comments To solve my doubts .

If the abstract method declared in an interface overrides the superclass
ObjectAny one of the classes public Method , Then these abstract methods will not be included in the number of abstract methods of the interface . Because the implementation of any interface will be from its parent classObjectOr get implementations of these methods elsewhere .- The interface also inherits
Object, So define in the interfaceequalsThe method is essentially rightObjectRewriting of ( Abstract rewrites concrete ). - If a class inherits its parent class at the same time , And implement the interface , And they have the same name method , Use Superclass priority

- The interface also inherits
/** * @Author: posper * @Date: 2022/07/20 15:49 */
public class Test {
public static void main(String[] args) {
Animal dog = new Dog();
// Superclass priority , So what is called here is the parent class Animal Medium run() Method
dog.run();
}
}
// verification “ Super class priority principle ”, see main() in dog.run() Method .
class Dog extends Animal implements Run {
int age;
String name;
}
// Interface
@FunctionalInterface
interface Run {
void run();
// Here's an analogy Comparator Medium equals,`@FunctionalInterface` It will not be regarded as an abstract method
@Override
boolean equals(Object o);
}
// Parent class
class Animal {
public void run() {
System.out.println(" call Animal Of run() Method ");
}
}
// verification “ Abstract rewrites concrete ”
abstract class Cat extends Animal {
// Abstract rewrites concrete methods , Yes, but it doesn't feel necessary ...
@Override
public abstract void run();
}
Running results :
边栏推荐
- Interface document evolution atlas, some ancient interface document tools, you may not have used them
- 简易订单管理系统小练习
- Redis (13) -- on master-slave replication of redis
- 【论文阅读】TEMPORAL ENSEMBLING FOR SEMI-SUPERVISED LEARNING
- 七月集训(第24天) —— 线段树
- WSDM 22 | 基于双曲几何的图推荐
- ICML2022 | 分支强化学习
- CMake基本语法(一)
- Aggregation measurement of robot swarm intelligence based on group entropy
- Knowledge sharing | sharing some methods to improve the level of enterprise document management
猜你喜欢

Data + AI summit 2022 PPT download

WSDM 22 | 基于双曲几何的图推荐

网络安全——Web信息收集

论文笔记:Swin-Unet: Unet-like Pure Transformer for MedicalImage Segmentation

Chinese character style transfer --- unsupervised typesetting transmission

汉字风格迁移篇---用于汉字多字体生成的多样性正则化StarGAN

On node embedding

The core capability of accelerating enterprise data application innovation flexibility

登临科技联合创始人王平:创新+自研“双核”驱动,GPU+赋能AI落地生根|量子位·视点分享回顾...

Unity UGUI中scroll bar在游戏中启动界面时没有从最上面显示
随机推荐
Icml2022 | branch reinforcement learning
Windivert:可抓包,修改包
Modern data architecture selection: Data fabric, data mesh
群体知识图谱:分布式知识迁移与联邦式图谱推理
Research and progress of traffic situation awareness based on social media data enhancement
Selenium environment configuration and eight elements positioning
LeadTools 22 kit LeadTools super set
爱可可AI前沿推介(7.24)
Mass data excel download - the author of this article only tried to download 510000 data, which took 7 seconds
Redis (13) -- on master-slave replication of redis
vscode配置用户代码片段(包括删除方法)
ESP32ADC
基于boost库的搜索引擎
网络安全——函数绕过注入
July training (day 24) - segment tree
Search engine based on boost library
C code specification
Data + AI Summit 2022 PPT 下载
ESP32ADC
Mongodb uses mongotemplate operations to add, delete, modify, query, page, sort, aggregate (including embedded data), file upload and download