FAQ
Hi,

If I have an interface A and a pointer to a struct B that suffices the
definition of A, I can do this:

var a A = new(B)

But I can't do this:

var map[string]A = make(map[string]*B)

Is this a way to make this kind of thing happen so that I can
functions that consume a map of A's, and fire maps of any type that
suffices the A contract into them?

Cheers,

Ben

PS Here's the play: http://play.golang.org/p/XSRW80bcRj

--
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

  • Jan Mercl at Nov 18, 2013 at 10:20 am

    On Mon, Nov 18, 2013 at 10:53 AM, Ben Hood wrote:
    Hi,

    If I have an interface A and a pointer to a struct B that suffices the
    definition of A, I can do this:

    var a A = new(B)

    But I can't do this:

    var map[string]A = make(map[string]*B)
    From http://golang.org/ref/spec#Assignability

    """"
    Assignability

    A value x is assignable to a variable of type T ("x is assignable to
    T") in any of these cases:

    - x's type is identical to T.
    - x's type V and T have identical underlying types and at least one of
    V or T is not a named type.
    - T is an interface type and x implements T.
    - x is a bidirectional channel value, T is a channel type, x's type V
    and T have identical element types, and at least one of V or T is not
    a named type.
    - x is the predeclared identifier nil and T is a pointer, function,
    slice, map, channel, or interface type.
    - x is an untyped constant representable by a value of type T.

    Any value may be assigned to the blank identifier.
    """"

    -j

    --
    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 18, '13 at 9:53a
activeNov 18, '13 at 10:20a
posts2
users2
websitegolang.org

2 users in discussion

Ben Hood: 1 post Jan Mercl: 1 post

People

Translate

site design / logo © 2021 Grokbase