On Tue, Aug 30, 2016 at 4:11 PM, <[email protected]> wrote:
>
> I see that interface{} is used in go's container/list
> https://golang.org/src/container/list/list.go
>
> In using this container am I expected to type assert the element's Value?
Yes.
> And is this pattern of returning an interface{} and then "casting" it
> typically accepted in practice to avoid duplication of larger code?
Pretty much, yes. It's a trade-off between code duplication and
compile-time type safety.
Note that in general you don't want to use container/list. Use a
slice instead. There are only a few special cases where
container/list is better than a slice. And if you use a slice you
don't need to worry about a type assertion.
Ian
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.