You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-dev@hadoop.apache.org by Owen O'Malley <ow...@yahoo-inc.com> on 2006/11/03 16:52:15 UTC
generic types
Hi all,
I've noticed a couple of people over-specifying the generic
collections. The general pattern is:
Map<Key,Value> myMap = new HashMap();
where the field is given a type of the general interface with the
type parameters and the constructor is the specific implementation
without the type parameters. The assignment works because in Java
(unlike C++) every T1<T2> extends T1. The advantage of the general
interface (eg. "Map" instead of "HashMap") is that if you change the
implementation later, you only need to change the constructor.
Thanks,
Owen