This is a creation in Article, where the information may have evolved or changed.
Objective:
Today will continue, the pit of their own digging must be filled, although the weather is very hot, but the slightest can not stop my pits enthusiasm, then, we continue to let us go!!!
Define the method:
Here we are going to look at the (Methods) method in Golang. We've talked about the Go language function (functions) in Go (ix), which is not a concept for today's approach. Familiarity with object-oriented students should know that, in general, we call the member function of the class methods (method). Go is an object-oriented language and of course there is this concept (although we haven't talked about Go's object-oriented programming yet). Said so much, for the code farm, code is the fastest way to show Ah, then immediately show you the code:
Oh yeah, in the above program, line 4th we define a new type of mystring, which is actually a string alias. Of course, you can define the type you want, such as the structure in the previous article.
The definition of this method seems to be different from the traditional object-oriented language, such as Java, and Java once you define a class, the corresponding Member method is also within the block of the class. The go language is more like a function bound to a type, see 12 lines (P person) getName () in the GetName before the method name is used () to pass a type to this method. This way the method becomes a method of the person. In this case, you have introduced yourself to the method, there is no need to have a Java this or Python self.
Summary:
Today this is, originally also want to write more, but still do not bother to write a lot of that kind of article, a day a little bit, make up ~
- author: Sirk
- source: http:// Www.cnblogs.com/vimsk
- this edition The right to the author and the blog Park is shared, welcome reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.
|