Go Type method Receiver Understanding

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.
Package Mainimport ' FMT ' type person struct{    name string age    int}func (this *person) growth () {    this.age ++}fu NC (This *person) changename (newname string) {    this.name = Newname}func Main () {    p: = person{"Wangzy", +}     p. Growth ()    FMT. Printf ("%d", P.age)}


Because go is not object-oriented, struct is not a class, there is no class method, but the method of the struct is provided by the type method, similar to the class method.


Can be called through the class instance. The feeling can be completely replaced

It can be passed in by reference parameters of the struct body.


It's hard to understand at first.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.