Go Type Aliasing

From NovaOrdis Knowledge Base
Revision as of 04:24, 13 April 2016 by Ovidiu (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Internal

Overview

An existing type can be used as the type specification of a new type.

Example:

type Duration int64

In the case above, Duration and int64 are considered two distinct and different types. Values of two types cannot assigned to each other, even if they are compatible.

The standard library uses this type declaration to create high-level functionality from built-in types. New behavior can be added to these type with methods. Aliasing types is necessary because the compiler will only allow declaring methods for user-defined types that are named.