Questions tagged «type-mismatch»

4
无法将数据(类型接口{})转换为字符串类型:需要类型断言
我还很新,我正在玩这个通知包。 最初,我有如下代码: func doit(w http.ResponseWriter, r *http.Request) { notify.Post("my_event", "Hello World!") fmt.Fprint(w, "+OK") } 我想将换行符添加到上面Hello World!的函数中doit,但不要添加,因为那将是微不足道的,但是在handler此后,如下所示: func handler(w http.ResponseWriter, r *http.Request) { myEventChan := make(chan interface{}) notify.Start("my_event", myEventChan) data := <-myEventChan fmt.Fprint(w, data + "\n") } 之后go run: $ go run lp.go # command-line-arguments ./lp.go:15: invalid operation: data + "\n" …
175 go  type-mismatch 

4
Scala上的类型不匹配以进行理解
为什么这种构造会在Scala中导致类型不匹配错误? for (first <- Some(1); second <- List(1,2,3)) yield (first,second) <console>:6: error: type mismatch; found : List[(Int, Int)] required: Option[?] for (first <- Some(1); second <- List(1,2,3)) yield (first,second) 如果我用列表切换Some,它可以很好地编译: for (first <- List(1,2,3); second <- Some(1)) yield (first,second) res41: List[(Int, Int)] = List((1,1), (2,1), (3,1)) 这也可以正常工作: for (first <- …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.