Hi,
I'm working with a project where I want to be able to add and remove
many objects within a list. Thus the built-in slice in Go would not be
a good approach because the operation of removing an object in the
middle of a slice is too heavy. I've been using the standard List
struct in Go (
http://golang.org/pkg/container/list/) but I think it
has several disadvantages compared to list classes in other languages.
The first disadvantage is that it is possible to store any kind of
object, and can thus not be limited to only one type of struct or to
one type of objects which fulfills some specific interface. Hence, you
might append an object to a list that has a type which you did not
intend to have in the list. The other disadvantage is that when you
want to loop over all objects in the list you cannot use the built in
clause range and you also have to explicitly convert the Value of an
Element (in the list) back to its original type before you can use it
as a normal object, which becomes very tedious after just a few times.
Is it possible to somehow use the reflect package in Go to get rid of
the disadvantages that I mentioned here or is the only way out of this
to wait for generic types to be implemented in Go (which will probably
never happen anyway..)?
Thanks in advance!