Hi

Why does the type of a parameter passed to another function changes?
For example:

func P(args ...interface{}) {
   print("\n", args)
}

func print(seperator string, args ...interface{}) {
   for _, arg := range args {
      fmt.Println("arg type: ", reflect.TypeOf(arg))

      str := ""
      switch v := arg.(type) {
      case byte:
         str = string(v)
      case rune:
         str = string(v)
      case int:
         str = strconv.Itoa(v)
      case int64:
         str = strconv.FormatInt(v, 10)
      case string:
         str = v
      }
      out.WriteString(str + seperator)
   }
}


Calling *P("one"[2]) *gives type as  *[]interface {}*
where as directly calling *print("one"[2]) *gives type as *byte*

*Why is it like this? *
*And any way i can achieve this without putting switch in P() function?*

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANFuhy-7NbdMw6UynmUS9HnakVpUaJ_SCP8vkr11Z27LcLnrPA%40mail.gmail.com.

Reply via email to