When you write [S []any], this means "S must have type []any". `[]int` has
type `[]int`, which is different from `[]any`, so this doesn't work - and
it can't work:
https://blog.merovius.de/posts/2018-06-03-why-doesnt-go-have-variance-in/

When you write [E any, S []E], you say "E must be any type and S must have
type []E". This *can* be instantiated using `[]int`, because `int` can take
the place of `E` (it is "any type") and then `[]int` has type `[]E` and
everything is great.

On Wed, May 11, 2022 at 5:45 PM Michel Casabianca <
michel.casabia...@gmail.com> wrote:

> Hi gophers!
>
> This code https://go.dev/play/p/QHIxegJn3aj doesn't compile. I don't
> understand why. Anyone would have an explanation? And why this code
> https://go.dev/play/p/PCSzRkLvXhp fixes it?
>
> Thanks for your replies
> Best regards
> --
> Michel Casabianca
>
> --
> 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/18738918-be16-4b0b-825e-e01f7d9c6225n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/18738918-be16-4b0b-825e-e01f7d9c6225n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAEkBMfEb2h5HDOvR7f_3eHvRJh3YQDPMJ6Lsd70_bQ6gcuvR9Q%40mail.gmail.com.

Reply via email to