Last active
July 5, 2023 01:36
-
-
Save reetasingh/33be8581989961d43e93d338ad7ca11c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func CreatePersonDB[T PersonDB](person Person) error { | |
db := new(T) | |
db.save(person) | |
return nil | |
} | |
func main() { | |
person := Person{ | |
ID: 101, | |
Name: "John D", | |
} | |
CreatePersonDB[LocalDatabase](person) | |
} | |
// will not compile | |
// ./prog.go:43:5: db.save undefined (type *T is pointer to type parameter, not type parameter) | |
// ./prog.go:52:17: LocalDatabase does not satisfy PersonDB (method save has pointer receiver) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment