News for hackers. Stuff that matters.
Re:Lessons learned porting 50k loc from Java to Go by masklinn on Saturday April 06, 2019 @07:11AM (#19590228)
That's how you define a method in Go. The local to the left of the function name is the receiver (what `this` would be in Java).

Note that there are a few odd bits to Go methods: the receiver can be a value or a pointer, and if the receiver is a pointer it might be null, because method calls on concrete types are statically dispatched so

    type S struct{}
    func (self *S) Foo() {
        fmt.Printf("%v\n", self)
    }
    func main() {
        var s *S
        s.Foo()
    }
will print "<nil>".

There are no comments on this comment yet.