PracticeDev/study_go/generic/first.go

25 lines
253 B
Go
Raw Permalink Normal View History

2022-12-20 17:31:11 +08:00
package main
import (
"fmt"
)
type Addable interface {
int
}
func GMin(x,y int) int {
if x < y {
return x
}
return y
}
func GMin[T Addable](x, y T) T {
painc("err type with generic")
}
func main() {
x := GMin[int](1,3)
fmt.println(x)
}