I was playing with Go generics and writing some codes, but I faced some problems. I want to ask questions and help from the community if possible. Below, I am trying to build a generic struct via a method through another generic struct.
Here's the link to Go Playground:
https://go.dev/play/p/Q0zOJUePkmR
---
package main
var _ I = (*A)(nil)
type I interface {
String() string
}
type A struct {
str string
}
func (a A) String() string {
return a.str
}
type AE[T, V I] struct {
T1 T
T2 V
}
// func (AE[T, V]) String() string {
// return "test"
// }
type Test[T, V A] struct{}
func (t Test[T, V]) S() AE[T, V] {
return AE[T, V]{}
}
func main() {}
---
I expected the program to run, but then I got an error:
T does not satisfy I (missing method String)
I a bit confused because A implements I interface. I think this must be because I missed something with the Go generics.
Thank you.