我认为解释这个问题的最好方法就是举例,所以这里是:
package main
import (
"fmt"
)
// Greeter greets with a Greeting.
type Greeter interface {
Greet() Greeting
}
// A Greeting has a string representation.
type Greeting interface {
String() string
}
type Hello struct {}
// Hello greets by returning itself...
func (h *Hello) Greet() *Hello {
return h
}
// ...because Hello also has a string representation.
func (h *Hello) String() string {
return "Hello"
}
// But Go says Hello doesn't implement Greeter.
func main() …
Run Code Online (Sandbox Code Playgroud)