Hacker News new | past | comments | ask | show | jobs | submit login

In Go, a type doesn't have to declare that it implements an interface; it automatically satisfies an interface if it implements the appropriate methods. Most interfaces in Go only contain one method.

If a type has a Close() method, then it is a Closer. The code that tries to cast it to a Closer will succeed. So to answer your question, it doesn't matter what the semantics of your Close() method are, it will succeed solely based on the fact that your type has a method with that name.




> your type has a method with that name.

I would say with the same function signature, not just the name.


Go doesn't support overloading. Method dispatch is done by name only.

http://golang.org/doc/faq#overloading


But interface satisfaction is by signature, not name, and that is what is being discussed, not method dispatch.


Sorry, I didn't mean to conflate the two. Thanks for the clarification.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: