Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
typeswitch2.go36 linesDownload Raw Back to typeparam
1// run2 3// Copyright 2021 The Go Authors. All rights reserved.4// Use of this source code is governed by a BSD-style5// license that can be found in the LICENSE file.6 7package main8 9import "fmt"10 11func f[T any](i interface{}) {12	switch x := i.(type) {13	case T:14		fmt.Println("T", x)15	case int:16		fmt.Println("int", x)17	case int32, int16:18		fmt.Println("int32/int16", x)19	case struct{ a, b T }:20		fmt.Println("struct{T,T}", x.a, x.b)21	default:22		fmt.Println("other", x)23	}24}25func main() {26	f[float64](float64(6))27	f[float64](int(7))28	f[float64](int32(8))29	f[float64](struct{ a, b float64 }{a: 1, b: 2})30	f[float64](int8(9))31	f[int32](int32(7))32	f[int](int32(7))33	f[any](int(10))34	f[interface{ M() }](int(11))35}36 
codekingpro/portable-devtools · Team Ai