learning_go/Lec19/main.go
2025-07-14 06:14:06 +03:00

38 lines
554 B
Go

package main
import "fmt"
type Student struct {
name string
age int
}
type Desriber interface {
Describe()
}
func (std Student) Describe(){
fmt.Printf("%s and %d y.o",std.name,std.age)
}
func TypeDescriber(i interface{}){
switch v := i.(type){
case string:
fmt.Println("I am string")
case int:
fmt.Println("I am int")
case Desriber:
fmt.Println("I am describer!")
v.Describe()
default:
fmt.Println("Unknown type but I still work!")
}
}
func main() {
TypeDescriber(9)
std := Student{"Alex", 19}
TypeDescriber(std)
}