Created
June 4, 2022 22:52
-
-
Save xeoncross/e8fbea4f1537bb1b0fdae7385fc79d74 to your computer and use it in GitHub Desktop.
Example of creating a string that implements an interface in Go / golang: https://go.dev/play/p/-IC8BGzjPPG
This file contains 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
package main | |
import "fmt" | |
type A string | |
func (a A) Foo() { | |
fmt.Printf("Foo: %q\n", a) | |
} | |
type Fooer interface { | |
Foo() | |
} | |
func main() { | |
var a Fooer | |
a = A("hello") | |
a.Foo() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment