I have two types of lists:
ArrayList<String> sList;
ArrayList<Resource rList;
I can call a .getName()
method on the resource object.
I want to be able to print out either of those lists by calling a printList(list)
metod like this:
printList(sList);
printList(rList);
And the code for them would look like this:
private static void printList(ArrayList<String> list){
for(String s : list){
System.out.println(s + ", ");
}
}
private static void printList(ArrayList<Resource> list){
for(Resource r : list){
System.out.println(r.getName() + ", ");
}
}
I don't have any particular reason for using private static
, it just happened to be like that because eclipse suggested it.
The code, however, does not work. Eclipse gives me following error:
"Method printList(ArrayList) has the same erasure printList(ArrayList) as another method in type GUI"
GUI
is my class. What is wrong?
EDIT: Is there any alternative or work-around to get the functionality I want?