jweinst1
1/29/2017 - 11:22 PM

string casting examples in go

string casting examples in go

package main

import "fmt"

//wraps a value in any type
func value(elem interface{}) interface{} {
  return elem
}

func str(elem interface{}) string {
  return elem.(string)
}

func main() {
  fmt.Println(value("hello world"))
  fmt.Println(value("hello world").(string) + " This is a string cast")
  fmt.Println(str(value("hello word")) + " this is another cast")
}