From: Andrew Gerrand
Date: Wed, 29 Jun 2011 04:58:01 +0000 (+1000)
Subject: [release-branch.r58] doc/faq: add question about converting from []T to []interface{}
X-Git-Tag: release.r58~7
X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=01a1c9169686deb54df6b73ee8dcdb1a5cb88634;p=gostls13.git
[release-branch.r58] doc/faq: add question about converting from []T to []interface{}
««« CL 4639046 / 995095e59d58
doc/faq: add question about converting from []T to []interface{}
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/4639046
»»»
R=r
CC=golang-dev
https://golang.org/cl/4630077
---
diff --git a/doc/go_faq.html b/doc/go_faq.html
index 953092f051..ef70033ace 100644
--- a/doc/go_faq.html
+++ b/doc/go_faq.html
@@ -598,6 +598,24 @@ the interface idea. Sometimes, though, they're necessary to resolve ambiguities
among similar interfaces.
+
+Can I convert a []T to an []interface{}?
+
+
+Not directly because they do not have the same representation in memory.
+It is necessary to copy the elements individually to the destination
+slice. This example converts a slice of int
to a slice of
+interface{}
:
+
+
+
+t := []int{1, 2, 3, 4}
+s := make([]interface{}, len(t))
+for i, v := range t {
+ s[i] = v
+}
+
+
Values