GoLang,MethodName之前括号内的内容是什么? [英] GoLang, what is contents in parenthesis before MethodName?
问题描述
func (t *T) MethodName(argType T1, replyType *T2) error
MethodName之前括号内的内容是什么?我的意思是这个(t * T)
what is contents in parenthesis before MethodName? I mean this (t *T)
这个来自这里: http://golang.org/pkg/net/rpc/
我试着理解golang rpc并看到了这个方法的定义。
This comes from here: http://golang.org/pkg/net/rpc/ I try to understand golang rpc and saw this method definition.
谢谢,
推荐答案
方法是一个带有接收器的函数。方法声明将
标识符(方法名称)绑定到方法,并将方法
与接收方的基本类型相关联。
A method is a function with a receiver. A method declaration binds an identifier, the method name, to a method, and associates the method with the receiver's base type.
给定类型Point,声明
Given type Point, the declarations
func (p *Point) Length() float64 {
return math.Sqrt(p.x * p.x + p.y * p.y)
}
func (p *Point) Scale(factor float64) {
p.x *= factor
p.y *= factor
}
将方法Length和Scale与接收器类型* Point绑定到
基本类型。
bind the methods Length and Scale, with receiver type *Point, to the base type.
这是接收方法。
这篇关于GoLang,MethodName之前括号内的内容是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!