Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Unfortunately I think copying 100K elements is going to be exactly as painful as it sounds. The `[]Impl` is going to be (more or less) an array of 100K strings. The `[]Abstract` will be an array of interfaces, each of which is internally two pointers, so I'll have to allocate 1.6M of RAM and fill that RAM with pointers in order to convert a `[]Impl` into a `[]Abstract`.

Generics fix this handily, because I can write:

    func ShowAbstracts[T Abstract](arr []T) {
       for _, a := range arr {
            fmt.Println(a.value())
        }
    }
And now when I try to pass in my `[]Impl`, Go will compile a new `ShowAbstracts(arr []Impl)` transparently behind the scenes.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: