3 ms·
Is there a difference in how or whether 'any' and 'interface{}' preserve static type information? i.e., if I implement `identity(a) = a` in a generic way, can
by mrkeen 3y ago
Is there a difference in how or whether 'any' and 'interface{}' preserve static type information?
i.e., if I implement `identity(a) = a` in a generic way, can I still call identity(duck).quack()?
- nh23423fefe 3y agoyes // You can edit this code! // Click here and start typing. package main import "fmt" func main() { duck := Duck{} identity(duck).quack() } func identity[T any](t T) T { return t } type Duck struct{} func (d Duck) quack() { fmt.Println("quack") } /* quack Program exited. */