interface

golang interface用法

golang interface测试 很不爽这种一眼看过去看不出一个struct实现了哪个interface的奇怪设计。但路依然是要走的,真香。。 测试代码1 package main import "fmt" type Task interface{ execute() } type CrontabTask struct{ } func (task CrontabTask) execute() { fmt.Println("crontab task!") } type QueueTask struct{ } func (task QueueTask) execute() { fmt.Println("queue task!") } type LoopTask struct{ } func (task LoopTask) execute() { fmt.Println("loop task!") } type WrongTask struct{ } func (task WrongTask) execute1() { fmt.Println("loop task!") } func main(){ var task Task task = new (CrontabTask) task.execut...
执行时间: 1710833968814.2 毫秒