为什么很多轮子里的函数多返回值,我可以只用一个变量去接受

forgolang · 2022-06-09 10:48:28 · 3026 次点击

好好看看编译器或者 VSCode 静态检查给出的错误提示

#21
更多评论
// You can edit this code!
// Click here and start typing.
package main

import "fmt"

func swap[A any, B any](a A, b B) (B, A) {
    return b, a
}

func main() {
    a, _ := swap(1, "Hello world")
    fmt.Println(a)
}


// Output
// Hello world
//
//Program exited.

https://go.dev/play/p/VotqVWcuonC 并没有发现这种情况

#1

@TBXark 你误会我的意思了,我说的是不用”_“接收会报错

#2