You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by Noel Grandin <no...@gmail.com> on 2009/04/13 16:24:33 UTC
type-inferencing factory methods for collection classes
Hi
There is a chance that this problem might be solved by Project Coin,
which may introduce compiler-driven constructor type inference into
Java 1.7.
But in the meantime.... what are the thoughts about introducing methods like
public clas HashMap {
public static <K, V> HashMap<K, V> create() {
return new HashMap<K, V>();
}
}
which help reduce unnecessary clutter like this:
private static final Map<Class<?>, BeanDictionary> defaultsCache =
new HashMap<Class<?>, BeanDictionary>();
to this
private static final Map<Class<?>, BeanDictionary> defaultsCache =
HashMap.create();
??
Re: type-inferencing factory methods for collection classes
Posted by Greg Brown <gk...@mac.com>.
-1
I see why you might want to add such a method, but I think that it might cause confusion. While this is verbose:
> private static final Map<Class<?>, BeanDictionary> defaultsCache =
> new HashMap<Class<?>, BeanDictionary>();
it is still clear that I'm simply invoking a generic constructor. This makes me wonder what else create() might be doing:
> private static final Map<Class<?>, BeanDictionary> defaultsCache =
> HashMap.create();