This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type student interface { | |
| register(context.Context, string, string, int) | |
| enrollCourse(uint32, time.Time) error | |
| pass(uint32) error | |
| fail(uint32) error | |
| } | |
| type alsoStudent interface { | |
| register(ctx context.Context, name, profession string, age int) | |
| enrollCourse(courseID uint32, start time.Time) error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface Vehicle { | |
| public void start(); | |
| public void stop(); | |
| } | |
| public class Car implements Vehicle { | |
| public void start() { | |
| System.out.println("starting engine..."); | |
| } | |
| public void stop() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Vehicle interface { | |
| Start() | |
| Stop() | |
| } | |
| type Car struct {} | |
| func (c *Car) Start() { | |
| fmt.Println("starting engine...") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type toaster interface { | |
| toast() | |
| } | |
| type acmeToaster struct {} | |
| func (a *acmeToaster) toast() { fmt.Println("Commencing toasting of bread...") } | |
| func doToast(t toaster) { | |
| t.toast() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Verify that acmeToaster satisfies interface toaster. | |
| var _ toaster = &acmeToaster{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type empty interface {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type monster struct { | |
| damage int | |
| } | |
| func (m *monster) attack() int { | |
| return m.damage | |
| } | |
| type attacker interface { | |
| attack() int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type toaster interface { | |
| toast() | |
| } | |
| type acmeToaster struct {} | |
| func (a *acmeToaster) toast() { fmt.Println("Commencing toasting of bread...") } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func doToast(t toaster) { | |
| t.toast() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type myError struct{} | |
| func (m *myError) Error() string { | |
| return "failure" | |
| } | |
| func doSomething() (string, *myError) { | |
| return "", nil | |
| } |