Golang syntax question on bracket use

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?


func (d Dog) Greet(animalToGreet Animal) {
if _, ok := animalToGreet.(Person); ok {

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.

thank you Dave!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.