-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.go
More file actions
62 lines (46 loc) · 715 Bytes
/
interface.go
File metadata and controls
62 lines (46 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import "fmt"
type Sayer interface {
say()
}
type Move interface {
move()
}
type dog struct {
name string
}
type cat struct{}
func (d dog) say() {
fmt.Println("Hello, dog!")
}
func (d dog) move() {
fmt.Println("dog move!")
}
func (c cat) say() {
fmt.Println("Hello, cat!")
}
func interfaceCase() {
fmt.Println("=====接口case=====")
var dogSayer dog
dogSayer.say()
//接口类型变量
var x Sayer
a := dog{}
b := cat{}
x = a
x.say()
x = b
x.say()
}
type People interface {
Speak(string) string
}
type StudentA struct{}
func (stu *StudentA) Speak(think string) (talk string) {
if think == "sb" {
talk = "你是个大帅比"
} else {
talk = "您好"
}
return
}