On Fri, Jan 12, 2018 at 7:23 PM, Peter Mogensen <a...@one.com> wrote: > > On 2018-01-12 19:09, 'Axel Wagner' via golang-nuts wrote: > > One would think the result is rather well defined. > > > > It's not. The value in the interface doesn't have to be a pointer, so > > this is, in general, not defined at all. > > No, but it's not like you cannot ask about interface{} in general. > I can do a type switch, asking: >
Yes, you can *test* if the dynamic value has a specific type (and extract it if so). That is not the same as operating on the dynamic value (e.g. by dereferencing it) *without* knowing its type. > Now I just wondered how to do something like a parameterized version of > that: > Go does not have parametrically polymorphic types - and even if it had, there wouldn't be any sensible type you could assume here, given that it's only known at runtime. There simply is no type that the extracted value could have. Like, what would the type of t be in your example, in the **<Something> case? When you say "well defined" you refer to that an interface{} can be > anything until you do reflection or type assertion. > > When I say "well defined", I speak of whether it's in general is > ambiguous what is meant. Yes, it is in general ambiguous what is meant. You *can* generically dereference a pointer, but you have to use reflection, which is the tool to be used on generic values that you don't know the type of: https://play.golang.org/p/73lJyOlaIdL I consider it unlikely that you actually want to do that, though. Unless you are writing some generic encoder, that can operate on any type. But the fact that you are asking about doubly-indirect pointer and dereferencing them one layer deep, seems to suggest that you actually want to use a specific type because you know what types you can have. -- 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.