check code below, How to use []interface{} in generic programing? type IReset interface { Reset() } type Fight struct { hp,mp int } func (my *Fight) Reset () { my.hp = 0 my.mp = 0 } func reset1(x IReset){ x.Reset() } func reset(x []IReset) { for i := range x { x[i].Reset() } } func Reset() { arr := make([]Fight,1) arr[0].hp = 100 reset1(arr[0])//OK reset(arr)// can not use []Fight as []IReset }
-- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.