Go allows methods to be defined on any named type, not just structs or objects. This includes primitive-backed types like custom integers (e.g., TimeZone based on int) and even function types. The net/http package's HandlerFunc is a real-world example of methods on a function type, implementing the ServeHTTP interface. This flexibility is highlighted as one of Go's most powerful features compared to languages that require wrapping primitives in objects.

2m read timeFrom boldlygo.tech
Post cover image
4 Impressions