使用 type-switch (代码来自The way to go)
switch a := arg.(type) { // type switch
case Stringer: os.Stdout.WriteString(a.String())
case int: os.Stdout.WriteString(strconv.Itoa(a))
case string: os.Stdout.WriteString(a)
// more types
default: os.Stdout.WriteString("???")
}
这种写法能把 arg.(type)换成 arg.TypeOf()可以吗 还有一个就是这个反射是不是就类似于 java 里的方法重载,根据传入的类型选择不同的处理方式?