3 ms·
> interface{} and any behavior differences, I'm curious now. They are type aliases. In which situations there is a difference in behavior?
by ithkuil 3y ago
> interface{} and any behavior differences,
I'm curious now. They are type aliases. In which situations there is a difference in behavior?
- mseepgood 3y agoThere are no differences. You can always substitute one for the other without change in behaviour. These two are interchangeable: func f[T any]() {} func f[T interface{}]() {} and these two are interchangeable: func f(x any) {} func f(x interface{}) {} Maybe OP means the difference between using an interface as type parameter constraint and using an interface as a function parameter / variable type.
- gabereiser 3y agoNo difference as any := interface{}
- parhamn 3y agoI was firing that list off the top of my head and I think that one was a mistake. My bad. But, I did recently have some weird typing issues around "satisfies" x vs "is" x and using new() constructors of the T in a generic functions (particularly de-alternative serialization of proto.Message types) and had quite a bit of frustration and confusion. That may have been on me, but I did open my statement with "[wish it had better docs]".