Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
17805ddb
Commit
17805ddb
authored
Jun 18, 2011
by
Andrew Gerrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc/faq: add question about converting from []T to []interface{}
R=golang-dev, r CC=golang-dev
https://golang.org/cl/4639046
parent
61f4ec13
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
0 deletions
+18
-0
doc/go_faq.html
doc/go_faq.html
+18
-0
No files found.
doc/go_faq.html
View file @
17805ddb
...
...
@@ -598,6 +598,24 @@ the interface idea. Sometimes, though, they're necessary to resolve ambiguities
among similar interfaces.
</p>
<h3
id=
"convert_slice_of_interface"
>
Can I convert a []T to an []interface{}?
</h3>
<p>
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
<code>
int
</code>
to a slice of
<code>
interface{}
</code>
:
</p>
<pre>
t := []int{1, 2, 3, 4}
s := make([]interface{}, len(t))
for i, v := range t {
s[i] = v
}
</pre>
<h2
id=
"values"
>
Values
</h2>
<h3
id=
"conversions"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment