In Go generics, how to use a common method for types in a union constraint?
Add the method to the interface constraint, without forgoing generics: type AB interface { *A | *B some() bool } func some[T AB](x T) bool { return x.some() // works } This restricts T to types that are either *A or *B and declare some() bool method. However, as you already found out, this is … Read more