Created
November 21, 2021 21:13
-
-
Save jordanorelli/385a6f5de1b914a4631e2899ea10d377 to your computer and use it in GitHub Desktop.
union elements in interfaces
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
jordan@wonkavator[1] ~: cat what.go | |
package main | |
import ( | |
"fmt" | |
) | |
type Smallboi interface { | |
int8 | int16 | |
} | |
func blep[T Smallboi](b T) { | |
fmt.Println(b) | |
} | |
func main() { | |
x := int8(12) | |
y := int16(15) | |
blep(x) | |
blep(y) | |
} | |
jordan@wonkavator[1] ~: go version | |
go version go1.17.3 linux/amd64 | |
jordan@wonkavator[1] ~: go run what.go | |
# command-line-arguments | |
./what.go:8:7: syntax error: unexpected |, expecting semicolon or newline or } | |
./what.go:11:6: missing function body | |
./what.go:11:10: syntax error: unexpected [, expecting ( | |
jordan@wonkavator[1] ~: go1.18 version | |
go version devel go1.18-91abe4be0e Sat Nov 20 08:47:36 2021 +0000 linux/amd64 | |
jordan@wonkavator[1] ~: go1.18 run what.go | |
12 | |
15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment