【文件属性】:
文件名称:go接口类型(interface)
文件大小:35KB
文件格式:PDF
更新时间:2021-01-06 04:59:19
ace c ce
接口 (Interfaces) 是命名了的方法签名 (signatures) 的集合
package main
import fmt
import math
// 这里是一个几何体的基本接口。
type geometry interface {
area() float64
perim() float64
}
// 在我们的例子中,我们将在类型 `rect` 和 `circle` 上实现
// 这个接口
type rect struct {
width, height float64
}
type circle struct {
radius float