comSysStudent 1 Light Poster

Hi all,

I'm working on a project where I will have 4 ArrayLists of different types of items(stock, sales etc.). I have one list done but there is going to be a lot of duplication between the 4 list types. I'm trying to create a List superclass which will accept the type of item I would like to populate the list with as an argument but I'm having difficulty with generics. So far I have

File fileLocation; 
	Scanner existingList; 
	ArrayList<? extends ListItem> listItems = new ArrayList<? extends ListItem>();
	PrintWriter listOutput;

        public List(String s) throws Exception
	{
		fileLocation = new File(s);
		importList();// method which imports items from file to arraylist if it already exists
	}

within my superclass. What I would like to be able to do is have all the methods in the superclass and be able to call something like super(Product) to create a list of products for the ProductList subclass and so on.

So ideally I would like to be able to have the salesList class constructor call on the List constructor, feed it a filename and a Type such as Receipt or Sale, and have the super constructor create a list of that type. Can this be accomplished?

This isn't a "please do my homework" post, I have the entire StockList class up and running and I'm quite pleased with it. I would just like to figure out how to use generics to cut out 4 nearly identical copy/pasted classes.

Many thanks in advance.