GNOME Bugzilla – Bug 663337
Allow to get Type of generic parameters in Collections, Maps and MultiMaps
Last modified: 2011-12-19 17:07:46 UTC
AbstractCollection<T> has a useful public data member: Type element_type = T.get_type (); (get_type() above only works for objects, but you get the idea) This makes it possible to handle AbstractCollections in an extra-generic way like: /* note that we don't specify the generic type for ac */ void some_func (AbstractCollection ac) { if (ac.element_type == typeof (string)) handle_string (); else if (ac.is_a (typeof (SomeInterface)) handle_some_interface (); else if (ac.element_type == typeof (Object)) handle_plain_objects (); else ... } However, MultiMap doesn't derive from AbstractCollection, so it doesn't have element_type. So to do the equivalent of above, it's necessary to first do: var multi_map_keys = prop_value_multi_map.get_keys (); var key_type = multi_map_keys.element_type; var multi_map_values = prop_value_multi_map.get_values (); var value_type = multi_map_values.element_type; At least in the values case, this allocates a new ArrayList, iterates all the values, and various other things that add unnecessary computation. So, please add the following members to MultiMap/AbstractMultiMap/HashMultiMap: Type key_type = K.get_type (); Type value_type = V.get_type ();
*** Bug 663339 has been marked as a duplicate of this bug. ***
Sorry for delay. It sounds like a good idea to use it in interface. It looks like it have been done before in Collection but I prefer to check why it was removed (and left only in AbstractCollection).
Also add Iterator to the list. I'm using an Iterator from some Javascript/gjs code now, and it'd be much nicer if I didn't have to explicitly state the element type in my binding.
commit b62ed44ad3be999ef1d663845589bbf9f31072b6 Author: Maciej Piechotka <uzytkownik2@gmail.com> Date: Mon Dec 19 17:58:29 2011 +0100 Add *_type property for all collections, fixes bug #663337