title: hadoop implementing a generic list writable
body: <p>I am working on building a map reduce pipeline of jobs(with one MR job's output feeding to another as input). The values being passed around are fairly complex, in that there are lists of different types and hash maps with values as lists. Hadoop api does not seem to have a ListWritable. Am trying to write a generic one, but it seems i can't instantiate a generic type in my readFields implementation, unless i pass in the class type itself:</p>
  
  <pre><code>public class ListWritable&lt;T extends Writable&gt; implements Writable {
      private List&lt;T&gt; list;
      private Class&lt;T&gt; clazz;
  
      public ListWritable(Class&lt;T&gt; clazz) {
         this.clazz = clazz;
         list = new ArrayList&lt;T&gt;();
      }
  
      @Override
      public void write(DataOutput out) throws IOException {
          out.writeInt(list.size());
          for (T element : list) {
              element.write(out);
          }
       }
  
       @Override
       public void readFields(DataInput in) throws IOException{
       int count = in.readInt();
       this.list = new ArrayList&lt;T&gt;();
       for (int i = 0; i &lt; count; i++) {
          try {
              T obj = clazz.newInstance();
              obj.readFields(in);
              list.add(obj);
          } catch (InstantiationException e) {
              e.printStackTrace();
          } catch (IllegalAccessException e) {
              e.printStackTrace();
          }
        }
      }
  }
  </code></pre>
  
  <p>But hadoop requires all writables to have a no argument constructor to read the values back. 
  Has anybody tried to do the same and solved this problem?
  TIA.</p>