I have a lot of Java 1.4 code, which I’m in the process of migrating to Java 5. I would like to fix all the compiler warnings about using raw types in parameterized classes, and am wondering if there is a tool that can automatically transform something like:
List myList = new ArrayList();
myList.add("foo");
String foo = (String) myList.get(0);
to:
List<String> myList = new ArrayList<String>();
myList.add("foo");
String foo = myList.get(0);
I understand that Generics are quite complex and therefore don’t expect that such a tool would be able to choose the most correct parameterized type in all cases. However, as long as it can handle simple cases (such as the above), and won’t break my code, I’ll be satisfied.
Similarly, I would like to change all the old-skool loops, to the simplified for loop introduced in Java 5.
Does such a tool exist?
I would do this using Eclipse.
Select the package structure you need to be upgraded, then right click -> Refactor -> Infer Generic Type Arguments
Imho it’s a starting point for what you need.