2021年1月19日星期二

What's the difference between generic and non-generic use of interfaces in Golang?

In the new generics proposal for Golang, you can now apply an interface constraint to a generic function:

func prettyPrint[T Stringer](s T) string {      ...  }  

But, this was already possible by using an interface parameter without generics:

func prettyPrint(s Stringer) string {      ...  }  

What's the difference between using the first and using the second?

https://stackoverflow.com/questions/65802110/whats-the-difference-between-generic-and-non-generic-use-of-interfaces-in-golan January 20, 2021 at 10:06AM

没有评论:

发表评论