to illustrate what Ian wrote, with your example:
https://go2goplay.golang.org/p/YTqF-WS0m6O
func main() {
var ps = []*Person{
&Person{"Arthur Dent", 42},
&Person{"Zaphod Beeblebrox", 9001},
}
Print(ps) // ok.
Printi(ps) // compilation error.
}
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Wednesday, December 23rd, 2020 at 7:02 PM, Ian Lance Taylor
<[email protected]> wrote:
> On Wed, Dec 23, 2020 at 9:54 AM wilk [email protected] 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.
>
> 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 [email protected].
>
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUALDVBWJwhHYxT6T5%3Dz2tvSKp7yMy%3DF4HSJc_uTZZKGQ%40mail.gmail.com.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/irhuBuJMF9HLWxoYcutqmZM8aZmKAhxUEX05kKplyqZ9N8wQtZNWtP41CfTJmXpmWGfo8qkEI-27xnYGykDbAcUlSyPrDskc2lB2Q5Pt-BA%3D%40sbinet.org.