mirror of
https://github.com/MADTeacher/go_basics.git
synced 2025-11-23 21:34:47 +02:00
21 lines
338 B
Go
21 lines
338 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"}
|
|
var secondInterface interface{} = "Oo"
|
|
|
|
fmt.Printf("%+v\n", secondInterface.(string)) // ok
|
|
fmt.Printf("%+v\n", firstInterface.(string)) // error
|
|
|
|
}
|