4
,因为我已经为2种不同的数据类型有类似的功能:通用功能
func GetStatus(value uint8) (string) {...}
func GetStatus(name string) (string) {...}
我想用一种方式更为简单,如:
func GetStatus(value interface{}) (string) {...}
可以创建一个使用接口的通用函数? 数据类型可以使用reflect.Typeof(value)
有没有一种方法来扩展它的更多类型?还是必须为我需要的每种类型写'case'? 就像'originalValue:= value。(reflect.TypeOf(value))'''可能吗? – 2016-03-02 18:06:47