In the following program, it is valid to pass an interface to function P: func P[T fmt.Stringer](x T) { fmt.Println(x) }
func main() { var v fmt.Stringer P(v) } However, there is no way for P to check if x is nil. This does not compile: func P[T fmt.Stringer](x T) { if x!=nil { fmt.Println(x) } } Is it possible to write a generic function that can test if its argument with a constraint is nil? -- 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/CAMV2Rqp3OV%2BOHTYJL3zkBbssktOSaRQDqz7fzSoeLU002YTZ1Q%40mail.gmail.com.