The following does not compile, but I believe it could be made to do so. 1. Note that "lists" is a private variable. 2. Note that "lists" is not passed as an argument to any method. 3. Note that each element of "lists" is assigned using the constructor ArrayList<String>() which matches the type of the declaration. Under these restrictions, I believe that generic array creation is safe. (These restrictions would naturally be satisfied by users of my class library. Implementing this RFE would allow me to generify my classes without causing customers to see unchecked warnings when creating arrays of my classes.) import java.util.*; public class GenericRfe { private ArrayList<String>[] lists = new ArrayList<String>[2]; public GenericRfe() { for (int i = 0; i < lists.length; ++i) { lists[i] = new ArrayList<String>(); } } public void add(String s) { lists[0].add(s); } public String get(int i) { return lists[0].get(i); } public static void main(String[] args) { GenericRfe gr = new GenericRfe(); gr.add("Testing"); String testing = gr.get(0); System.out.println(testing); } } ###@###.### 2005-2-16 02:39:59 GMT
|