Go嵌入类型及内部提升样例
2024-09-01 04:52:24
这个有点新鲜哟。。。
package main import ( "fmt" ) type notifier interface { notify() } type user struct { name string email string } func (u *user) notify() { fmt.Printf("Sending user email to %s<%s>\n", u.name, u.email) } type admin struct { user level string } func (a *admin) notify() { fmt.Printf("Sending admin email to %s<%s>\n", a.name, a.email) } //main is the entry of the program func main() { ad := admin { user: user { name: "john smith", email: "john@yahoo.com", }, level: "super", } sendNotification(&ad) ad.user.notify() ad.notify() } func sendNotification(n notifier) { n.notify() }
最新文章
- Win10提示没有权限使用网络资源问题解决
- MVP模式(Android)
- qt qml ajax 获取 json 天气数据示例
- NOIp 2013 #3 转圈游戏 Label:模拟
- JQuery兼容IE6问题汇总(不断更新)
- 详解Python对象属性
- (int),Int32.Parse() 和 Convert.toInt32() 的区别
- Linux信号(signal) 机制分析
- HTTP基础:URL格式、 HTTP请求、响应、消息
- python学习第十一天 -- 函数式编程
- jQuery 1.9+ ajaxStart事件无效,无法被触发的原因。
- (简单) LightOJ 1074 Extended Traffic,SPFA+负环。
- STL中的二分查找———lower_bound,upper_bound,binary_search
- [51nod1673]树有几多愁
- eclipse版本对应的jdk版本
- 定时调度系列之Quartz.Net详解
- Node.js_ express.Router 路由器_模块化管理路由
- redis----------基本命令使用
- k8s中yaml文常见语法
- Objective-C市场占有率排名升至第4位