当前位置:网站首页>Go从入门到实战——多态(笔记)
Go从入门到实战——多态(笔记)
2022-06-27 19:22:00 【积淀 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)
}
边栏推荐
- Can Oracle's CTAs bring constraints and other attributes to the new table?
- How to do a good job of gateway high availability protection in the big promotion scenario
- oss上传调用的是哪个方法
- SQL server for circular usage
- SQL Server for循环用法
- Go从入门到实战——Context与任务取消(笔记)
- Serveur mandataire SQUID
- Ceph分布式存储
- KDD 2022 | 图“预训练、提示、微调”范式下的图神经网络泛化框架
- 白嫖红队goby&POC,叫你如何白嫖?
猜你喜欢
squid代理服務器
SQL server for circular usage
让马化腾失望了!Web3.0,毫无希望
Serveur mandataire SQUID
猜拳游戏专题训练
Here are 12 commonly used function formulas for you. All used ones are good
Very comprehensive dolphin scheduler installation and use documents
Covering access to 2w+ traffic monitoring equipment, EMQ creates a new digital engine for all elements of traffic in Shenzhen
2021全球独角兽榜发布:中国301家独角兽企业全名单来了!
GFS distributed file system
随机推荐
Zhongang Mining: the largest application field of new energy or fluorite
1029 Median
农产品期货怎么做怎么开户,期货开户手续费多少,找谁能优惠手续费?
OpenSSL 编程 二:搭建 CA
01-Golang-环境搭建
Let Ma Huateng down! Web3.0, hopeless
一套系统,减轻人流集中地10倍的通行压力
Experience Navicat premium 16, unlimited reset, 14 day trial method (with source code)
This is the same as data collection. Can you define a parameter as last month or the previous day, and then use this parameter in SQL?
DO280OpenShift访问控制--security policy和章节实验
GoLand永久激活
Codeforces Round #716 (Div. 2)
GFS distributed file system
KDD 2022 | 图“预训练、提示、微调”范式下的图神经网络泛化框架
Use the storcli tool to configure raid. Just collect this article
非常全面的DolphinScheduler(海豚调度)安装使用文档
Shell command used in actual work - sed
通过CE修改器修改大型网络游戏
VMware vSphere esxi 7.0 installation tutorial
事件相关电位ERP的皮层溯源分析