Generics

I'm new to generics and wondering what I'm doing makes any sense at all.

publicclass ACHFile<Bextends ACHBatch>{

private List<B> batches =new ArrayList<B>();

public List<B> getBatches(){return batches;}

}

publicclass ACHBatch<Eextends ACHEntry>{

private List<E> entries;

public ACHBatch(){}

public List<E> getEntries(){return entries;}

publicvoid setEntries(List<E> entries){ this.entries = entries;}

}

publicclass ACHEntry{}

publicclass CTXBatchextends ACHBatch{

public CTXBatch(){ setEntries(new ArrayList<CTXEntry>);}

}

publicclass CTXEntryextends ACHEntry{}

So, an instance of ACHFile will contain a collection of some subclass of ACHBatch:

ACHFile<CTXBatch> f =new ACHFile<CTXBatch>();

CTXBatch knows what kind of entries it's supposed to contain:

setEntries(new ArrayList<CTXEntry>);

But I get this warning on the above statement:

Type safety: The field entries from the raw type ACHBatch is assigned a value of type ArrayList<E>. References to generic type ACHBatch<E> should be parameterized.

This makes me think I'm probably taking a bad approach to this problem. Am I missing something obvious here, or should I be rethinking this whole approach?

Thanks...

[2887 byte] By [twocoasttba] at [2007-11-26 17:09:15]
# 1

The class ACHBatch has a parameterized type. When you extend it you should declare what that parameterized type is, otherwise you're using the "raw" type ACHBatch and you'll get a warning. In your example the declaration should probably look like this:

public class CTXBatch extends ACHBatch<CTXEntry>

kablaira at 2007-7-8 23:37:04 > top of Java-index,Java Essentials,Java Programming...
# 2
Thank you; that was a big help...
twocoasttba at 2007-7-8 23:37:04 > top of Java-index,Java Essentials,Java Programming...