X
X
x32net2016-12-15 11:28:23
go
x32net, 2016-12-15 11:28:23

How to create a pointer to a list of pointers by interface?

So I create a list of pointers by interface.

package main

import (
  "fmt"
  "reflect"
)

type Example struct {
  Name string
}

func main() {
  p := new(Example)
  r := reflect.TypeOf(p)
  t := reflect.SliceOf(r)
  s := reflect.New(t).Elem().Interface()

  x := new([]*Example)

  fmt.Printf("%#v = %#v\n", x, s)
}

https://play.golang.org/p/5r_HJt7JHc

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey K, 2016-12-15
@x32net

package main

import (
  "fmt"
  "reflect"
)

type Example struct {
  Name string
}

func main() {
  p := new(Example)
  r := reflect.TypeOf(p)
  t := reflect.SliceOf(r)
  s := reflect.New(t).Interface()

  x := new([]*Example)

  fmt.Printf("%#v = %#v\n", x, s)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question