hjma29
(Hongjun Ma)
April 4, 2017, 1:22am
1
I’m trying to figure out what the following line mean in line 48 of the code. why there is a bracket around (Person). What does Person do here for Animal Interface?
https://play.golang.org/p/m_RQeo9N1H
func (d Dog) Greet(animalToGreet Animal) {
if _, ok := animalToGreet.(Person) ; ok {
dfc
(Dave Cheney)
April 4, 2017, 1:40am
2
This is a type assertion, https://golang.org/ref/spec#Type_assertions
It asserts that the value inside the Animal interface is indeed a Person type.
system
(system)
Closed
July 3, 2017, 4:04am
4
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.