Go에서 인터페이스 변환의 존재 이유가 잘 이해가 안가는데


package main

type Walkable interface {
walk()
}

type Human struct {
}

func (h *Human) walk() {
}

type Warrior struct {
sword string
}

func (w *Warrior) walk() {
println("is walking.")
}

func walkAndAttack(walker Walkable) {
if w, ok := walker.(*Warrior); !ok {
println("I can't walk.")
} else {
w.walk()
println("My sword is", w.sword)
}
}

func main() {
warrior := &Warrior{sword: "Excalibur"}
walker := &Human{}

walkAndAttack(warrior)
walkAndAttack(walker)
}

이렇게 인터페이스에서 구현체를 유추할 수 있잖아. 이 문법이 있는 이유를 잘 모르겠는데


그냥 Go에서의 instanceof나 as 타입캐스팅이라고 이해하면 됨?