当前位置:网站首页>Interface as a parameter (interface callback)
Interface as a parameter (interface callback)
2022-07-07 08:22:00 【Cold_ Chuan】
interface Animal {
void eat();
}
@Slf4j
class Cat implements Animal {
@Override
public void eat() {
log.debug(" Cats eat fish ");
}
}
@Slf4j
class Dog implements Animal {
@Override
public void eat() {
log.debug(" Dogs eat meat ");
}
}
class AnimalTest {
// Interface as a parameter
public void AnimalEat(Animal animal) {
animal.eat();
}
}
Realization
@Test
public void interfaceCallbackTest(){
Animal1 cat = new Cat(); //Cat Class implements the Animal1, be Animal1 Point to Cat Object address of class
Animal2 dog = new Dog(); //Dog Class implements the Animal2, be Animal2 Point to Dog Object address of class
AnimalTest animalTest = new AnimalTest();
animalTest.AnimalEat(cat); // It's actually calling theta cat Of eat() Method Cats eat fish
animalTest.AnimalEat(dog); // It's actually calling theta dog Of eat() Method Export dogs to eat meat
}
Animal1 cat = new Cat(); The so-called interface callback , namely Which class implements it , It points to the object address of which class
animalTest.AnimalEat(cat); The animal interface finds the address of the cat's object , Call the cat's eating method
边栏推荐
- 复杂网络建模(一)
- GFS分布式文件系统
- Interview questions (CAS)
- 快解析内网穿透为文档加密行业保驾护航
- Using nocalhost to develop microservice application on rainbow
- offer收割机:两个长字符串数字相加求和(经典面试算法题)
- 【雅思口语】安娜口语学习记录 Part2
- Offer harvester: add and sum two long string numbers (classic interview algorithm question)
- Qinglong panel -- finishing usable scripts
- 基于Pytorch 框架手动完成线性回归
猜你喜欢

eBPF Cilium实战(2) - 底层网络可观测性

Splunk子查询模糊匹配csv中字段值为*

Uniapp mobile terminal forced update function

柯基数据通过Rainbond完成云原生改造,实现离线持续交付客户

Caractéristiques de bisenet

Notes on PHP penetration test topics

一文了解如何源码编译Rainbond基础组件

CDC (change data capture technology), a powerful tool for real-time database synchronization

Fast parsing intranet penetration escorts the document encryption industry

Interpreting the practical application of maker thinking and mathematics curriculum
随机推荐
One click installation of highly available Nacos clusters in rainbow
Open3D ISS关键点
One click deployment of highly available emqx clusters in rainbow
Application of slip ring of shipborne radar antenna
Vulnerability recurrence fastjson deserialization
What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit
在Rainbond中实现数据库结构自动化升级
Caractéristiques de bisenet
The use of generics and vararg variable parameters in kotlin
PVTV2--Pyramid Vision TransformerV2学习笔记
Domain specific language / DSL in kotlin
Battery and motor technology have received great attention, but electric control technology is rarely mentioned?
Using nocalhost to develop microservice application on rainbow
Complex network modeling (III)
Call pytorch API to complete linear regression
使用BiSeNet实现自己的数据集
Complex network modeling (I)
解读创客思维与数学课程的实际运用
Easy to understand SSO
XCiT学习笔记