Interfaces

Implicit interface satisfaction

A concrete type implements a basic interface when its method set contains compatible methods. No explicit implements declaration is required. A blank-identifier assignment can assert this property at compile time without invoking a method. Example output: 'Ada'.

Formal Syntax & Structure

go syntaxgo
var _ Interface = (*Concrete)(nil)

Working Example

Example Snippetgo
package main
import "fmt"
type Namer interface{ Name() string }type User struct{ label string }
func (u User) Name() string { return u.label }
var _ Namer = User{}
func main() {  var n Namer = User{"Ada"}  fmt.Println(n.Name())}
Go Reference