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

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

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

#2
更多评论
// 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

是不是你没用_接,起了个名,但是没用到

#3