FTR, you can also pass an actual []Usable, instead of a []tmpType. That is do https://play.golang.org/p/N_CJh0Ekik8 But I do think that your code and question suggest that you are trying to use interfaces to do some sort of subtyping, which is just not how they are supposed to be used.
On Wed, Jan 31, 2018 at 6:43 PM, Axel Wagner <axel.wagner...@googlemail.com> wrote: > You have to use reflection for that. Go doesn't have subtyping of that > kind. This smells a bit of an xy-problem <http://xyproblem.info/> to me, > though. There are several things here, that suggest an antipattern going > on. With a little bit of context on the actual problem you are trying to > solve, we might be able to come up with a more idiomatic design. > > On Wed, Jan 31, 2018 at 6:37 PM, Chris Hopkins <cbehopk...@gmail.com> > wrote: > >> Hi >> Sharing my ignorance: >> I didn't realise that although you can switch-case on an interface, an >> array of interfaces doesn't work. >> https://play.golang.org/p/tD8msjCXyuZ >> >> Any ideas on how to cope with this? I tried: >> _, ok = tmp.([]Useable) >> >> But that fails for the same reason. I can't work out how to detect if the >> type (of the empty interface) is an array of a type that satisfies the >> (useful) interface. >> This must be a common problem and PEBKAC surely? >> >> Regards >> >> Chris >> >> -- >> 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. >> > > -- 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.