I'm trying to make a wrapper in go for the map[] type so that I can add some methods like contains() (this almost makes me miss java). However, I don't know how I can do anything like generics in java.
While almost everything I've read says that golang doesn't have generic types, there must be a better way than writing a separate struct for every single possible combination of structs and values that I'm using.
Here's what I'm trying to do, even though the code doesn't work:
func newMap(key interface{}, val interface{}) {
keytype := key.(type)
valtype := val.(type)
return hashmap{map[keytype]valtype}
}
type hashmap struct {
hashmap map[]
}
Any help/explanation on how to do this would be appreciated.
EDIT: Contains isn't the only thing I'm trying to replicate, hence the desire to make a "generic" hashmap. replace(), isEmpty(), all that fun stuff as well.