Created
July 23, 2020 04:49
-
-
Save Jagua/2be9ab1d3a00aa318a4d045631e3af42 to your computer and use it in GitHub Desktop.
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 addable interface { | |
type int, string | |
} | |
func add(type T addable)(x, y T) T { | |
return x + y | |
} | |
func main() { | |
fmt.Printf("%d + %d = %d\n", 1, 1, add(1, 1)) // 1 + 1 = 2 | |
fmt.Printf(`"%s" + "%s" = "%s"` + "\n", "1", "1", add("1", "1")) // "1" + "1" = "11" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment