Type system

Go interface types

Defines a type set. Basic interfaces can be used as value types; non-basic interfaces are restricted to constraints. A concrete type implements an interface implicitly by satisfying its requirements. Example output: 'item'.

Formal Syntax & Structure

go syntaxgo
interface { Method() T }

Working Example

Example Snippetgo
package main
import (  "fmt")
type label int
func (l label) String() string { return "item" }func main() {  var x interface{ String() string } = label(3)  fmt.Println(x.String())}
Go Reference