xxxxxxxxxx
import "golang.org/x/exp/constraints"
func GMin[T constraints.Ordered](x, y T) T {
if x < y {
return x
}
return y
}
xxxxxxxxxx
package main
import "fmt"
type SingleGeneric[T any] struct {
Hobby T `json:"hobby"`
}
type MultipleGeneric[T any, U any] struct {
Name T `json:"name"`
Age U `json:"age"`
h SingleGeneric[string]
}
func Testing[T any](data T) T {
return data
}
func main() {
multiple := MultipleGeneric[string, uint]{}
multiple.Name = "John doe"
multiple.Age = 20
multiple.h.Hobby = "Badminton"
fmt.Println(multiple)
testing := Testing[string]("hello wordl 2")
fmt.Println(testing)
}