天天看点

Golang的fallthrough与switch的坑

最近写Golang的是发现一个fallthrough与switch的坑:

<code>switch</code> <code>value.(type) {</code>

<code>    </code><code>case</code> <code>int</code><code>:</code>

<code>        </code><code>fallthrough</code>

<code>    </code><code>case</code> <code>int64:</code>

<code>        </code><code>//......</code>

<code>}</code>

编译就报错:

<code>cannot fallthrough in type </code><code>switch</code>

WHAT????

在type switch 中不能使用

<code>fallthrough</code>

只能修改代码:

<code>    </code><code>case</code> <code>int</code> <code>, int64:</code>

本文转自 梦朝思夕 51CTO博客,原文链接:http://blog.51cto.com/qiangmzsx/1932845