1
0
mirror of https://github.com/MADTeacher/go_basics.git synced 2025-11-23 21:34:47 +02:00
Files
go_basics/part_3/3.9/4.go
2025-06-04 18:38:52 +03:00

31 lines
495 B
Go

package main
import "fmt"
type shape struct {
name string
}
func (s *shape) getName() string {
return s.name
}
func main() {
var firstInterface interface{} = shape{name: "Cube"}
value, ok := firstInterface.(string)
if ok {
fmt.Println(value) // работаем со значением
} else {
fmt.Println("Wrong type assertion!")
}
newValue, newOk := firstInterface.(shape)
if newOk {
fmt.Println(newValue.getName())
} else {
fmt.Println("Wrong type assertion!")
}
}