Last active
July 4, 2023 23:33
-
-
Save reetasingh/961d1dad62b5359fb7bc0704876c8b3e 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:42:5: db.save undefined (type *T is pointer to type parameter, not type parameter) | |
Go build failed. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment