3

GO 语言中神秘的函数传参问题

 2 years ago
source link: https://www.v2ex.com/t/802817
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Go

GO 语言中神秘的函数传参问题

  cookgo · 2 天前 · 1744 次点击

首先展示一下代码:

package main

import "fmt"

type Obj1 struct {

}

type Callback1 func(interface{})
type Callback2 func(*Obj1)

func handle1(a int,fn Callback1)  {
	//do nothing
}

func handle2(a int,fn Callback2)  {
	//do nothing
}

func logic(o *Obj1) {
	fmt.Println(o)
}

func main() {
	handle1(1,logic)
	handle2(2,logic)
}

为什么 handle1 函数会编译不通过,interface{}不是可以代表任意类型吗?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK