6 ms·
> Not cast to just a concrete type, but to an interface. Literally duck typing. That's not duck typing, though. It's similar but not the same. With duck typi
by jlarocco 2y ago
> Not cast to just a concrete type, but to an interface. Literally duck typing.
That's not duck typing, though. It's similar but not the same.
With duck typing there isn't an interface to cast to, but the runtime object has a method matching the one being called. If you're casting, then it's not real duck typing.
People often imagine a "metaclass" or "meta-interface" for each method to help understand how duck typing works, but it's just a mental model to understand the concept. In reality there is no interface tying the methods together, and the whole thing is done at runtime, along with a runtime error if the method doesn't exist.
- deleted 2y ago[deleted]
- randomdata 2y ago> If you're casting, then it's not real duck typing. 'If' being the operative word. You're not actually casting. That was merely to not try and confuse the commenter further. In fact, Go doesn't even support casting! It does support type conversion, which is oft confused with casting, but that uses the syntax `type(variable)`, which is not what is going on here either. > In reality there is no interface tying the methods together, and the whole thing is done at runtime, along with a runtime error if the method doesn't exist. Right, which is how it works.