I am confused how copying of interface works. Here is an example:

type Interface interface {

type S struct {
a []int
b float64

func NewS(length int, alpha float64) S {
return S{ make([]int, length), alpha }

func (s S) DoSomething() {

func main() {
s1 := NewS(10, 1.0)
s2 := s1 // Here we create a new copy of S
var i1 Interface
i1 = s1

i2 := i1

Here my question is:

    1. as S implement Interface (not *S), when we assign s1 to i1, are we
    making a new copy of S for i1 to point to, or i1 will point to s1?
    2. when we assign i1 to i2, will i1 and i2 point to the same S object,
    or different ones?

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

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 6 | next ›
Discussion Overview
groupgolang-nuts @
postedJan 17, '14 at 7:19p
activeJan 18, '14 at 7:15a



site design / logo © 2021 Grokbase