Andrew's Digital Garden

Types in Go

Types can be helpful when two different things shared the same format (e.g. primitive type), but have a different meaning. The keyword type is followed by the name of the new type, followed by the underlying type that the new type is made of.

type km float64

It's possible to convert between types, if the types share the same underlying type.

A type based off another type will not share methods of the original type to the new type.

[[20200720152312-go-methods]]

[[go]]

Types in Go