Skip to content

Instantly share code, notes, and snippets.

@ivancorrales
Last active April 12, 2022 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivancorrales/7e7bcc260b3ea55ee18f0607e17dc37f to your computer and use it in GitHub Desktop.
Save ivancorrales/7e7bcc260b3ea55ee18f0607e17dc37f to your computer and use it in GitHub Desktop.
Go generics: any
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