当前位置:网站首页>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
边栏推荐
- Using helm to install rainbow in various kubernetes
- Complex network modeling (III)
- [quick start of Digital IC Verification] 10. Verilog RTL design must know FIFO
- Battery and motor technology have received great attention, but electric control technology is rarely mentioned?
- The use of generics and vararg variable parameters in kotlin
- [step on the pit series] H5 cross domain problem of uniapp
- BiSeNet的特點
- Game attack and defense world reverse
- buureservewp(2)
- 探索STEAM艺术设计中的创造力
猜你喜欢
Improve the delivery efficiency of enterprise products (1) -- one click installation and upgrade of enterprise applications
[IELTS speaking] Anna's oral learning records part2
Explore creativity in steam art design
漏洞複現-Fastjson 反序列化
Réplication de vulnérabilité - désrialisation fastjson
Game attack and defense world reverse
rsync远程同步
拓维信息使用 Rainbond 的云原生落地实践
opencv学习笔记四——膨胀/腐蚀/开运算/闭运算
Vulnerability recurrence easy_ tornado
随机推荐
Rainbond 5.6 版本发布,增加多种安装方式,优化拓扑图操作体验
BiSeNet的特点
Avatary's livedriver trial experience
在Rainbond中实现数据库结构自动化升级
Use of out covariance and in inversion in kotlin
Open3D ISS关键点
opencv学习笔记三——图像平滑/去噪处理
Leetcode 187 Repeated DNA sequence (2022.07.06)
Zcmu--1396: queue problem (2)
Tuowei information uses the cloud native landing practice of rainbow
Fast parsing intranet penetration escorts the document encryption industry
快解析内网穿透为文档加密行业保驾护航
Coquette data completes the cloud native transformation through rainbow to realize offline continuous delivery to customers
Using nocalhost to develop microservice application on rainbow
DeiT学习笔记
一文了解如何源码编译Rainbond基础组件
CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand
数据库实时同步利器——CDC(变化数据捕获技术)
Call pytorch API to complete linear regression
Rainbond结合NeuVector实践容器安全管理