我有以下代码:
type ActorState int
const (
Unverified ActorState = 1 + iota
Verified
Banned
)
我想在我的实施中这样做。
i := 1
a : ActorState
a = ActorState(i)
但我收到错误Cannot convert expression of type int, error to type ActorState
。
我如何转换呢?
答案 0 :(得分:8)
你的语法错了,你的意思是
i := 1
a := ActorState(i)
或
i := 1
var a = ActorState(i)
或
i := 1
var a ActorState
a = ActorState(i)