On Tue, Feb 6, 2024 at 6:43 AM Victor Manuel “Vitu” Giordano <vitucho3...@gmail.com> wrote: > > I'm wondering why the language allow me to write something like this: > > type IncFunc func(a int) int > > type Incrementor interface { > IncFunc // <-- THIS is allowed > IncQuantity() int > } > > (RTR example here) > > I don't get how I can make leverage of that.. or if has any sense at all 🥴😵💫 > As I recall an interface is a set of methods, and a method do have a name... > the thing here is that the name if the name of the type not the function's > name.
An interface type like that can be used as a constraint for a type parameter. It can't be used as the type of a variable. As a type parameter constraint it means that the type argument must be IncFunc. It's fairly useless, but follows from the other rules about type parameter constraints. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUS1V4ss%3D9tbAOxMBpCxNoFunJPgF_pgYFZw_%3DAB_%3DPOw%40mail.gmail.com.