Created
September 10, 2017 13:17
-
-
Save kanapuli/7d9446a0fb70dc4c12675969cdfb4644 to your computer and use it in GitHub Desktop.
Types in Go
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 cat string | |
//String from type cat always meows | |
func (c cat) String() string { | |
return fmt.Sprintln("A Cat always Meows") | |
} | |
type tiger cat | |
func main() { | |
tom := cat("Tommy") | |
fmt.Printf("%s\n", tom) | |
kan := tiger("Kan") | |
fmt.Printf("%s\n", kan) | |
} | |
//Output | |
//go run main.go | |
//A Cat always Meows | |
//Kan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment