mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
more clear explanation for interface (#2779)
more clear explanation why interface is consider defined without specifically declaring it (like in other languages `pair implement Stringer`)
This commit is contained in:
parent
e78e41ce30
commit
801484a23b
@ -295,7 +295,7 @@ type pair struct {
|
|||||||
x, y int
|
x, y int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define a method on type pair. Pair now implements Stringer.
|
// Define a method on type pair. Pair now implements Stringer because Pair has defined all the methods in the interface.
|
||||||
func (p pair) String() string { // p is called the "receiver"
|
func (p pair) String() string { // p is called the "receiver"
|
||||||
// Sprintf is another public function in package fmt.
|
// Sprintf is another public function in package fmt.
|
||||||
// Dot syntax references fields of p.
|
// Dot syntax references fields of p.
|
||||||
|
Loading…
Reference in New Issue
Block a user