当前位置:网站首页>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
边栏推荐
- JS复制图片到剪切板 读取剪切板
- Domain specific language / DSL in kotlin
- 单场带货涨粉10万,农村主播竟将男装卖爆单?
- 数据库实时同步利器——CDC(变化数据捕获技术)
- 解析机器人科技发展观对社会研究论
- [step on the pit series] H5 cross domain problem of uniapp
- 复杂网络建模(三)
- Learn how to compile basic components of rainbow from the source code
- Hisense TV starts the developer mode
- Detailed explanation of apply, also, let, run functions and principle analysis of internal source code in kotlin
猜你喜欢

Interactive book delivery - signed version of Oracle DBA work notes

Register of assembly language by Wang Shuang
![[step on the pit series] H5 cross domain problem of uniapp](/img/53/bd836a5c5545f51be929d8d123b961.png)
[step on the pit series] H5 cross domain problem of uniapp

Rainbond 5.6 版本发布,增加多种安装方式,优化拓扑图操作体验

Tuowei information uses the cloud native landing practice of rainbow

Hisense TV starts the developer mode

JS cross browser parsing XML application
![[quick start of Digital IC Verification] 14. Basic syntax of SystemVerilog learning 1 (array, queue, structure, enumeration, string... Including practical exercises)](/img/60/011b3ccdffa978d691436449a99e10.png)
[quick start of Digital IC Verification] 14. Basic syntax of SystemVerilog learning 1 (array, queue, structure, enumeration, string... Including practical exercises)

Complex network modeling (I)

使用SwinUnet训练自己的数据集
随机推荐
Vulnerability recurrence easy_ tornado
Use of out covariance and in inversion in kotlin
[quick start of Digital IC Verification] 13. SystemVerilog interface and program learning
Wang Zijian: is the NFT of Tencent magic core worth buying?
eBPF Cilium实战(1) - 基于团队的网络隔离
Qinglong panel - today's headlines
IELTS review progress and method use [daily revision]
Caractéristiques de bisenet
What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
【Go ~ 0到1 】 第七天 获取时间戳,时间比较,时间格式转换,Sleep与定时器
[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)
CTF-WEB shrine模板注入nmap的基本使用
The reified keyword in kotlin is used for generics
Ebpf cilium practice (2) - underlying network observability
BiSeNet的特点
jeeSite 表单页面的Excel 导入功能
漏洞複現-Fastjson 反序列化
Full text query classification
Uniapp mobile terminal forced update function