cannot convert t (type interface {}) to type string: need type assertion

来源:互联网 发布:娃娃幼儿园软件 编辑:程序博客网 时间:2024/06/05 09:47

问题:
在使用interface表示任何类型时,如果要将interface转为某一类型,直接强制转换是不行的,例如:

var t interface{} = "abc"s := string(t)

cannot convert t(type interface {}) to type string: need type assertion

这样是不行的,需要进行type assertion类型断言,具体使用方法请参考:
golang 任何类型interface{}

更多信息:
http://blog.csdn.net/lanyang123456/article/details/78070886

阅读全文
0 0
原创粉丝点击