为类型添加方法
package main
import "fmt"
type powerInt int
func (m powerInt) isZero()bool{
return m == 0
}
func main() {
var num powerInt = 0
fmt.Println(num.isZero()) //true
num = 1
fmt.Println(num.isZero()) //false
}
最后更新于
package main
import "fmt"
type powerInt int
func (m powerInt) isZero()bool{
return m == 0
}
func main() {
var num powerInt = 0
fmt.Println(num.isZero()) //true
num = 1
fmt.Println(num.isZero()) //false
}
最后更新于