Interfaces
Interface embedding
Embedding interfaces intersects their type sets and combines their method requirements. Embedded methods with the same name must have identical signatures. For runtime interface values, the resulting interface must be basic. Example output: 'data ok'.
Formal Syntax & Structure
go syntaxgo
type Both interface { Reader; Writer }Working Example
Example Snippetgo
package main
import "fmt"
type Reader interface{ Read() string }type Writer interface{ Write() string }type Both interface { Reader Writer}type Device struct{}
func (Device) Read() string { return "data" }func (Device) Write() string { return "ok" }func main() { var v Both = Device{} fmt.Println(v.Read(), v.Write())}