On 23-12-2020, Ian Lance Taylor wrote:
> On Wed, Dec 23, 2020 at 9:54 AM wilk <w...@flibuste.net> wrote:
>>
>> https://go2goplay.golang.org/p/fTW3hJYNgfU
>>
>> type Stringer interface {
>>    String() string
>> }
>>
>> Print[T Stringer](s []T)
>>
>> Print(s []Stringer)
>>
>> Both forms works.
>> How to prevent double way to do the same things that can be confusing ?
>
> Both forms work but they mean two different things.
>
> Print(s []Stringer) takes a slice of the type Stringer.
>
> Print[T Stringer](s []T) takes a slice of some type T, where T
> implements Stringer.
>
> For example, if MyInt implements Stringer, and I have a []MyInt, then
> I can call Print[T Stringer](s []T) but I can't call Print(s
> []Stringer), because a []Stringer is not a []MyInt.

I understand the differences. But i'm affraid someone who never used
Go before will use type parameters instead of interface which is more
idiomatic i think.
I mean it will be difficult to say, you could use type parameters but
you should use interface, or something like that...
I'm speaking about ease of learn Go2.

-- 
wilk

-- 
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/rs08pp%24p8m%241%40ciao.gmane.io.

Reply via email to