当前位置:网站首页>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
边栏推荐
- Complex network modeling (II)
- Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu
- The truth of robot education in hands-on practice
- 在 Rainbond 中一键安装高可用 Nacos 集群
- 数据库实时同步利器——CDC(变化数据捕获技术)
- Blob 對象介紹
- 柯基数据通过Rainbond完成云原生改造,实现离线持续交付客户
- The largest 3 same digits in the string of leetcode simple question
- Tuowei information uses the cloud native landing practice of rainbow
- Caractéristiques de bisenet
猜你喜欢
CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand
PVTV2--Pyramid Vision TransformerV2学习笔记
Rainbow combines neuvector to practice container safety management
提高企业产品交付效率系列(1)—— 企业应用一键安装和升级
Vulnerability recurrence easy_ tornado
Tuowei information uses the cloud native landing practice of rainbow
拓维信息使用 Rainbond 的云原生落地实践
[step on the pit series] H5 cross domain problem of uniapp
机器人教育在动手实践中的真理
[IELTS speaking] Anna's oral learning records part2
随机推荐
Caractéristiques de bisenet
调用 pytorch API完成线性回归
Myabtis_ Plus
Understanding of out covariance, in inversion and invariance in kotlin
【雅思口语】安娜口语学习记录 Part2
云原生存储解决方案Rook-Ceph与Rainbond结合的实践
Quick analysis of Intranet penetration helps the foreign trade management industry cope with a variety of challenges
Hisense TV starts the developer mode
Use of any superclass and generic extension function in kotlin
Rainbond 5.6 版本发布,增加多种安装方式,优化拓扑图操作体验
It's too true. There's a reason why I haven't been rich
BiSeNet的特点
Snyk 依赖性安全漏洞扫描工具
Bayes' law
解读创客思维与数学课程的实际运用
What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit
【Go ~ 0到1 】 第七天 获取时间戳,时间比较,时间格式转换,Sleep与定时器
Battery and motor technology have received great attention, but electric control technology is rarely mentioned?
单元测试报告成功率低
接口作为参数(接口回调)