another example

tags: learning go programming

content

  • another way to think of implicitly satisfy is:

Note

  • as long as a type has the full set of signatures that an interface defines, the type satisfies the interface
  • even if the creator of the type doesn’t even know the existence of the interface!
  • we have:
type MyType struct {
	field string
}
func (m MyType) String() string {
	return field
}
  • in this example, I just created MyType
  • and, MyType satisfies Stringer interface
    • even when Stringer does NOT exist the code at all!

up

down

reference