I get a warning in eclipse for the following method:
public void clearArray(ArrayList a){
a.clear();
}
warning:
ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized
The code executes just fine, but I was wondering if this is an actual issue or just a wierd eclipse thing…
In general, it’s better to indicate the exact type of a Collection (ArrayList in this case) if you know it beforehand; you do that using generic types.
In the particular method you’re showing it might not be a big help, but in other situations (for instance, if you need to add elements to the ArrayList) the extra effort is worth, since it will help the compiler catch errors (like adding the wrong type of elements to the ArrayList). Also, it will make casts unnecessary when you’re getting the elements out of the ArrayList.
For the particular case of your example, fix the warning like this:
Of course,
Stringis just an example, instead use the actual type of the elements you’re storing in the ArrayList.