语言学习之method(The way to go)"/>
Go语言学习之method(The way to go)
生命不止,继续go go go !
在golang的世界中,一定要区分 方法和函数。
Go中没有类的概念,但是我们可以在一些类型上定义一些方法,也就是所谓的方法,跟函数不同。
通过func关键字声明方法
type Vertex struct {X, Y float64
}func (v Vertex) Abs() float64 {return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
type X struct{}func (x *X) test(){println("hi!", x)
}
方法的使用
更多推荐
Go语言学习之method(The way to go)
发布评论