DEV Community

Cover image for Is Golang duck typed?
Alex Rios
Alex Rios

Posted on

Is Golang duck typed?

Hum... Not really!

It's a common misunderstanding because in fact it can relate to the duck type mantra:

If it looks like a duck and quacks like a duck, it's a duck

We can achieve this effect this way

Ok but what is the difference?

Well, the duck typing is resolved in runtime (ruby, python) while in Go it occurs in compile time.

Because of that, in Go it is called structural typing
(sometimes you'll find it named as signature-based polymorphism).

Top comments (0)