The only time I "needed" generics was for an r-tree container I wrote.
I'd been much happier if I could statically catch my errors about contained
data type, instead of catching them at runtime with panics during
conversion.
For example:
x := 0.0
y := 0.0
data := 1
container := NewRTree()
container.Add(x, y, data)
found := container.FindNearest(x, y) // found type is interface{}
data2 := found.(float32) // THIS PANICS AT RUNTIME, data2 is int
Maybe something like this would be better:
container := NewRTree<float32>()
container.Add(x, y, data) // compile error: data is int, should be
float32
If there is another solution instead generics to solve this problem, I'd be
equally happy.
Ignazio
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.