当前位置:网站首页>Go from introduction to practice - polymorphism (note)
Go from introduction to practice - polymorphism (note)
2022-06-27 21:37:00 【Accumulated Ytu】
package main
import (
"fmt"
"testing"
)
type Code string
type Programmer interface {
WriteHelloWorld() Code
}
type GoProgrammer struct {
}
func (p *GoProgrammer) WriteHelloWorld() Code {
return "fmt.Println(\"Hello world\")"
}
type JavaProgrammer struct {
}
func (p *JavaProgrammer) WriteHelloWorld() Code {
return "System.out.Println(\"Hello world\")"
}
func writeFirstProgram(p Programmer) {
fmt.Printf("%T %v\n", p, p.WriteHelloWorld())
}
func TestPolymorphism(t *testing.T) {
goProg := new(GoProgrammer)
javaProg := new(JavaProgrammer)
writeFirstProgram(goProg)
writeFirstProgram(javaProg)
}
边栏推荐
- MySQL performance optimization index function, hidden, prefix, hash index usage (2)
- Go从入门到实战——channel的关闭和广播(笔记)
- Can Oracle's CTAs bring constraints and other attributes to the new table?
- MySQL usage notes 1
- 100 important knowledge points that SQL must master: filtering data
- Full record of 2022 open source moment at Huawei partners and Developers Conference
- SQL必需掌握的100个重要知识点:检索数据
- 100 important knowledge points that SQL must master: creating calculation fields
- 抖音的兴趣电商已经碰到流量天花板?
- Day8 ---- 云资讯项目介绍与创建
猜你喜欢

集合代码练习

White whoring red team goby & POC, how do you call white whoring?

银河麒麟系统局域网文件共享教程

Industry case | see the operation of bank digital transformation from the king of retail

Codeforces Round #717 (Div. 2)

After being forced to develop the app within 20 days, the group was laid off, and the technical director angrily criticized it: I wish "closure as soon as possible!"

Kirin V10 installation font

Go从入门到实战——package(笔记)

Go from introduction to practice - Interface (notes)

Go from entry to practice -- CSP concurrency mechanism (note)
随机推荐
快递e栈——数组篇小型项目
释放开源数据库创新力量 | 【甘肃】openGauss Meetup圆满结束
Kirin V10 installation font
oss上传调用的是哪个方法
mysql使用笔记一
Full record of 2022 open source moment at Huawei partners and Developers Conference
Is it safe to open an account and buy stocks? Who knows
SQL server for circular usage
让马化腾失望了!Web3.0,毫无希望
After being forced to develop the app within 20 days, the group was laid off, and the technical director angrily criticized it: I wish "closure as soon as possible!"
Go from entry to practice -- CSP concurrency mechanism (note)
通过CE修改器修改大型网络游戏
io流代码
Modify large online games through CE modifier
银河麒麟系统局域网文件共享教程
专题教程——选队长游戏
100 important knowledge points that SQL must master: combining where clauses
Codeforces Round #722 (Div. 2)
Experience Navicat premium 16, unlimited reset, 14 day trial method (with source code)
Go from introduction to actual combat - all tasks completed (notes)