Source file
test/typeparam/typeswitch5.go
1
2
3
4
5
6
7 package main
8
9 type myint int
10 func (x myint) foo() int {return int(x)}
11
12 type myfloat float64
13 func (x myfloat) foo() float64 {return float64(x) }
14
15 func f[T any](i interface{}) {
16 switch x := i.(type) {
17 case interface { foo() T }:
18 println("fooer", x.foo())
19 default:
20 println("other")
21 }
22 }
23 func main() {
24 f[int](myint(6))
25 f[int](myfloat(7))
26 f[float64](myint(8))
27 f[float64](myfloat(9))
28 }
29
View as plain text