Last active
April 12, 2022 18:19
-
-
Save ivancorrales/7e7bcc260b3ea55ee18f0607e17dc37f to your computer and use it in GitHub Desktop.
Go generics: any
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" | |
"reflect" | |
) | |
func echo[T any](v T) { | |
fmt.Printf("%v (%s)\n", v, reflect.TypeOf(v)) | |
} | |
func main() { | |
var vInt32 int32 = 120 | |
var vFloat32 float32 = 0.35 | |
var vString string = "John Doe" | |
var vBool bool = false | |
echo(vInt32) | |
echo(vFloat32) | |
echo(vString) | |
echo(vBool) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment