Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```go
- package main
- import (
- "fmt"
- )
- func main() {
- // slice of string
- sl := []string{"one", "two"}
- // make memory len(sl) for slice of interface
- var sliceOfIntf []interface{} = make([]interface{}, len(sl))
- // copy data from slice of string to slice of interface
- for i, d := range sl {
- sliceOfIntf[i] = d
- }
- // .... and slice of interface to interface
- var intf interface{} = sliceOfIntf
- // result print
- fmt.Printf("Interface: %v\nInterface in real: %#v\n\n", intf, intf)
- // How to get data?
- fmt.Print("=== OUTPUT ===\n")
- for k, v := range intf.([]interface{}) {
- fmt.Printf("%v -> %v\n", k, v)
- }
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement