
本文共 4197 字,大约阅读时间需要 13 分钟。
Golang ������������������������������������������������������������
Golang ���������������������������������������������������������������struct���������������interface���������������function���������������������user-defined types������������������������������������������������������������������������������������������������������������������������������������������������������������������
1. ������������������������������������
��� Go ��������������������������������������������������������������������������������������������������������������������������������������������������������� type
������������������������������������������������������������������������������������������������
������������������������������������������ objMap
������������������������������������������ X
��� Y
������������������ int
��� string
���
type objMap struct { X int Y string}
������������type m objMap
��������������������������������� m
��������������������� objMap
������������������������������������������������������������������������������������������������������������������������������������������������
2. ������������������������
��� Go ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
2.1 ������������
���������������������������
func ������([������������] ���������) [������������] { ���������}
���������������������������
���������(������)
������������������������������������������ add
��������������������������� int
���������������������������������
func add(x int, y int) int { return x * y}
������������������������������������������������������������������������������������������������������������������������������������ public
������������
public func add(x int, y int) int { return x * y}
2.2 ������������
���������������������������������������������������������������������������������������������
func ([������] ���������) ���������([������������] ���������) [������������] { ���������}
���������������������������
������.���������(������)
������������������������������������������ Abs
��������������������������� MyFloat
������������������������������������
type MyFloat float64func (f MyFloat) Abs() float64 { if f < 0 { return float64(-f) } return float64(f)}
���������������������������������������������������������������
func (ax *ageVal) testAge2() int { *ax = *ax * 8 return 0}
������������������������������������������������������������
3. ������������������������������
������������������������������������������������������������������������������������������������������������������������������
type Abst interface { Abs()}
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
3.1 ���������������������
������������������������������������������������
type MyFloatx float64type Mapx struct { X, Y float64}func (f MyFloatx) Abs() float64 { return float64(f * 2)}func (v *Mapx) Abs() float64 { return v.X + v.Y}var a MyFloatx = 2var b Mapx { X: 2, Y: 6,}a = a.Abs()b = b.Abs()
���������������������Abs
��������������� MyFloatx
��� Mapx
���������������������������������������
4. ���������������������������������
��� Go ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
type F func(int, int) int
������������������������������������������������������������������������������������������������������������
5. ������
��������������������� Golang ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� Golang ������������������������������
发表评论
最新留言
关于作者
