摘要: Polymorphic Array: package main import ( "fmt" ) type USB interface { Start() Stop() } type Phone struct { Name string } func (p *Phone) Start() { fmt 阅读全文
posted @ 2022-05-18 18:40 ascertain 阅读(15) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" "math/rand" "sort" "time" ) // Vale Vale结构体 type Vale struct { Name string Age int } func (vale Vale) String() string { re 阅读全文
posted @ 2022-05-18 18:22 ascertain 阅读(17) 评论(0) 推荐(0) 编辑
摘要: 结构体的接口实现方法参数为指针类型时,会报编译错误 package main type USB interface { method() } type Vale struct { } func (vale *Vale) method() { // 指针类型 println("vale method" 阅读全文
posted @ 2022-05-18 16:40 ascertain 阅读(15) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" ) type Calculator struct { N1, N2 float64 } func (c *Calculator) Print(n int) { for b := 1; b <= n; b++ { for p := 1; p <= 阅读全文
posted @ 2022-05-18 10:34 ascertain 阅读(14) 评论(0) 推荐(0) 编辑