知识卡片

普通读书笔记卡 · 4545.d.1.a

方法接收者决定可用方法

理解等级:中级

方法在函数签名前增加接收者,为定义类型附加行为。值接收者操作值副本,指针接收者可修改所指对象;方法集合影响接口满足关系。纠正原文的绝对提醒:可寻址的值调用某些指针接收者方法时,语言允许隐式取地址,但这不意味着值类型的方法集合也包含这些方法。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Go Language Foundations · 查看原书依据

      The declaration syntax for a method is very similar to that of a function, except that it includes an extra receiver argument before the function name that specifies the type that the method is attached to. When the method is called, the instance is accessible by the name specified in the receiver. For example, our

    参考来源

    - 位置:《Cloud Native Go》第03章《Go Language Foundations》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch03.xhtml) - 结论依据:方法在函数签名前增加接收者,为定义类型附加行为。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。 - 原始内容:The declaration syntax for a method is very similar to that of a function, except that it includes an extra receiver argument before the function name that specifies the type that the method is attached to. When the method is called, the instance is accessible by the name specified in the receiver. For example, our