美文网首页
golang interface 转 string,int,fl

golang interface 转 string,int,fl

作者: luckyase | 来源:发表于2018-07-20 15:45 被阅读0次

    golang interface 转 string,int,float64,其他类型
    golang interface convert to other type

    func interface2String(inter interface{}) {
    
        switch inter.(type) {
    
        case string:
            fmt.Println("string", inter.(string))
            break
        case int:
            fmt.Println("int", inter.(int))
            break
        case float64:
            fmt.Println("float64", inter.(float64))
            break
        }
    
    }
    
    func main() {
        interface2String("jack")
        interface2String(1)
        interface2String(12.223)
    }
    
    
    
    string jack
    int 1
    float64 12.223
    

    相关文章

      网友评论

          本文标题:golang interface 转 string,int,fl

          本文链接:https://www.haomeiwen.com/subject/kpkqmftx.html