named type
A new type you declare with the type keyword, based on an existing one, such as type state int.
In more detail
The new type has the same underlying data but is distinct to the compiler, so a state cannot be mixed with a plain int by accident. You can attach methods to it. Structs and interfaces are usually declared this way too.
Example
type state intRelated terms
- iota — A Go keyword usable only inside a const block, where it counts 0, 1, 2 and so on, used to number a set of related constants.
- struct — A Go type that groups named fields of different types into one value, such as a Target with a Name and a Port.
- method — A function that belongs to an object or type and is called on a value of it, as in name.upper().
- static typing — A language rule that every variable has one fixed type, known when the program is compiled, so type mistakes are caught before it runs.
Taught in
- Variables, Typing, and Zero Values — Concurrent Systems Programming with Go
- Structs and Methods — Concurrent Systems Programming with Go
- Interfaces and Why They Are Implicit — Concurrent Systems Programming with Go