Type Methods

Let's learn about the type methods in Go.

Introduction

A type method is a function that is attached to a specific data type. Although type methods (or methods on types) are, in reality, functions, they are defined and used in a slightly different way.

Note: The methods on types feature gives some object-oriented capabilities to Go, which is very handy and is used extensively in Go. Additionally, interfaces require type methods to work.

Defining new type methods is as simple as creating new functions, provided that we follow certain rules that associate the function with a data type.

Get hands-on with 1200+ tech skills courses.