FAQ

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.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 2 | next ›
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 © 2022 Grokbase