Answers for "dynamic type checking in golang"

Go
1

dynamic type checking in golang

func dynamicTypeChecking(value interface{}) {
	switch t := value.(type) {
	case string:
		fmt.Printf("string value is: %q\n", t)
	case int:
		fmt.Printf("int value is: %d\n", t)
	case float64:
		fmt.Printf("float value is: %f\n", t)
	default:
		fmt.Printf("default value is: %q\n", t)
	}
}

func main() {
  	dynamicTypeChecking("test")
  	dynamicTypeChecking(123)
	dynamicTypeChecking(123.44545)
}
Posted by: Guest on July-25-2021

Browse Popular Code Answers by Language