[csu540-f05-rpf] csu540f05 - arraylist help

Robert Futrelle futrelle at ccs.neu.edu
Mon Nov 21 21:33:30 EST 2005


Parameterization (generics) only work in Java 5.  I think you
said you're not using Java 5.  If you look at the API for
Java 1.4, you'll get the answer.  ArrayList in 1.5 seems
to be backwards compatible, as I guess it has to be (!).
So a line of the following form (pre-generics) should work
just fine:

    ArrayList triArray = new ArrayList();

Default is capacity of 10 elements, but you can use an integer arg
to start it off larger.

So it's simpler than you thought.  Of course you have to cast
everything you get out of it, because it only returns type
Object.

For example, the following compiles under Java 1.5:


import java.util.*;

public class Hoo {

  	public void hoo() {
		ArrayList a = new ArrayList();
	}
}


  -- RPF


>Hi,
>
>Anyone know how to create an array list of triangle objects
>
>ArrayList<Tri> triArray = new ArrayList<Tri>(1);
>
>is giving me the following problem "The type ArrayList is not generic;
>it cannot be parameterized with arguments <Tri>"
>
>
>Simon
>
>_______________________________________________
>csu540-f05-rpf mailing list
>csu540-f05-rpf at lists.ccs.neu.edu
>https://lists.ccs.neu.edu/bin/listinfo/csu540-f05-rpf




More information about the csu540-f05-rpf mailing list