GoLang,MethodName之前括号内的内容是什么? [英] GoLang, what is contents in parenthesis before MethodName?

查看:441
本文介绍了GoLang,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.

谢谢,

推荐答案


Go编程语言规范

方法声明

方法是一个带有接收器的函数。方法声明将
标识符(方法名称)绑定到方法,并将方法
与接收方的基本类型相关联。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆