Golang的fallthrough與switch的坑

最近寫Golang的是發現一個fallthrough與switch的坑:

switch value.(type) {
    case int:
        fallthrough
    case int64:
        //......
}

編譯就報錯:

cannot fallthrough in type switch

WHAT????

在type switch 中不能使用

fallthrough

只能修改代碼:

switch value.(type) {
    case int , int64:
        //......
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章