FAQ
Can't Go determine if two types are equivalent if they have the same
type-signature? I'm obviously doing something wrong....

type T []interface{}
m := make(map[string]interface{})
m["z"] = T{ "a", "b" }
if v,ok := m["z"].([]interface{}); ok { fmt.Println(v[0]) } // prints
if v,ok := m["z"].(T); ok { fmt.Println(v[1]) } // doesn't print

Prints 'b' but not 'a'.

http://play.golang.org/p/qI6XqhIawF

I'd expect both to be printed, as the type T is an []interface{}, right?

(My google-fu seems broken, just point me at any relevant thread if you
can...)

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Rob Pike at Nov 14, 2013 at 8:42 pm
    The type of the actual value stored in the map is T, not []interface.
    Static type vs. dynamic type. You might benefit from reading the early
    sections of http://blog.golang.org/laws-of-reflection.

    -rob

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jesse van den Kieboom at Nov 14, 2013 at 10:16 pm
    You can't type assert, but you can type
    convert: http://play.golang.org/p/CoClmpoWBu
    On Thursday, November 14, 2013 9:42:31 PM UTC+1, Rob Pike wrote:

    The type of the actual value stored in the map is T, not []interface.
    Static type vs. dynamic type. You might benefit from reading the early
    sections of http://blog.golang.org/laws-of-reflection.

    -rob
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Orthopteroid at Nov 14, 2013 at 10:51 pm
    Thanks guys. The extra reading is good - and conversion is likely what I
    need.


    On Thu, Nov 14, 2013 at 2:16 PM, Jesse van den Kieboom
    wrote:
    You can't type assert, but you can type convert:
    http://play.golang.org/p/CoClmpoWBu

    On Thursday, November 14, 2013 9:42:31 PM UTC+1, Rob Pike wrote:

    The type of the actual value stored in the map is T, not []interface.
    Static type vs. dynamic type. You might benefit from reading the early
    sections of http://blog.golang.org/laws-of-reflection.

    -rob
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 14, '13 at 8:37p
activeNov 14, '13 at 10:51p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase