go - cannot use temp (type interface {}) as type []string in argument to equalStringArray: need type assertion -


i'm trying pass string array method. although passes assertion, i'm getting error

cannot use temp (type interface {}) type []string in argument equalstringarray: need type assertion 

code:

if str, ok := temp.([]string); ok {     if !equalstringarray(temp, someotherstringarray) {         //     } else {         // else     } } 

i've tried checking type reflect.typeof(temp) , that's printing []string

you need use str, not temp

see: https://play.golang.org/p/t9aur98ks6

package main  func equalstringarray(a, b []string) bool {     if len(a) != len(b) {         return false     }     := 0; < len(a); i++ {         if a[i] != b[i] {             return false         }     }     return true }  func main() {     someotherstringarray := []string{"a", "b"}     var temp interface{}     temp = []string{"a", "b"}     if strarray, ok := temp.([]string); ok {         if !equalstringarray(strarray, someotherstringarray) {             // 1         } else {             // else         }     } } 

Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -