Add code
This commit is contained in:
parent
0c63b698be
commit
6a315ca521
2 changed files with 20 additions and 0 deletions
2
4-empty-interface-in-go/Makefile
Normal file
2
4-empty-interface-in-go/Makefile
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
all:
|
||||||
|
go run main.go
|
18
4-empty-interface-in-go/main.go
Normal file
18
4-empty-interface-in-go/main.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var i interface{}
|
||||||
|
describe(i)
|
||||||
|
|
||||||
|
i = 42
|
||||||
|
describe(i)
|
||||||
|
|
||||||
|
i = "hello"
|
||||||
|
describe(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func describe(i interface{}) {
|
||||||
|
fmt.Printf("(%v, %T)\n", i, i)
|
||||||
|
}
|
Reference in a new issue