Automatic code upgrade to Java 5

I have a lot of Java 1.4 code on which I am switching to Java 5. I would like to fix all the compiler warnings about using raw types in parameterized classes, and I 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);

at

List<String> myList = new ArrayList<String>();
myList.add("foo");
String foo = myList.get(0);

I understand that Generics are quite complex and therefore do not expect such a tool to be able to select the most correct parameterized type in all cases. However, if it can handle simple cases (like above) and won't break my code, I will be satisfied.

Similarly, I would like to change all the old-skool loops to a simplified loop introduced in Java 5.

Is there such a tool?

+3
source share
2 answers

Eclipse.

, , โ†’ โ†’

- , .

+7

, - @SuppressWarnings ( "rawtypes" ) . 1.4 ( ), , , . values suppresswarnings.

@SuppressWarnings("rawtypes") 
public class MyClass {}

.

for, for for , . . ? , , , :)

-2

Source: https://habr.com/ru/post/1755554/


All Articles