learning_go/spec_course/Lec19/main.go
a.pivkin 0635aaa5ae kk
2025-07-16 08:15:26 +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)
}