Hacker News new | ask | show | jobs
by ithkuil 999 days ago
> interface{} and any behavior differences,

I'm curious now. They are type aliases. In which situations there is a difference in behavior?

2 comments

There 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.
No difference as any := interface{}
I 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]".