1. func interface2String(inter interface{}) {
    2. switch inter.(type) {
    3. case string:
    4. fmt.Println("string", inter.(string))
    5. break
    6. case int:
    7. fmt.Println("int", inter.(int))
    8. break
    9. case float64:
    10. fmt.Println("float64", inter.(float64))
    11. break
    12. }
    13. }
    14. func main() {
    15. interface2String("jack")
    16. interface2String(1)
    17. interface2String(12.223)
    18. }
    1. string jack
    2. int 1
    3. float64 12.223

    image.jpeg