java - Changing the return type of a method based on the type of objects in the list -


i want refactor code non-typed objects typed objects.

for example, here current code:

public class testclass {      arraylist list = new arraylist();      public arraylist testmethoda() {         list.add("string1");         list.add("string2");         list.add("string3");         list.add("string4");         list.add("string5");         return list;     } } 

i want turn typed list, becomes

public class testclass {      list<string> list = new arraylist<>();      public arraylist<string> testmethoda() {         list.add("string1");         list.add("string2");         list.add("string3");         list.add("string4");         list.add("string5");         return list;     } } 

is there way change return type arraylist arraylist<object> based on type of obj1, obj2, ...]? example, if what's being added list of type string, possible change return value arraylist arraylist<string> dynamically?

i'm using eclipse, if there plugin (or script or something) can me appreciated.

if there no 'automatic' way of doing mean 5-6 days of manual fixing, rather avoid.

in java editor: right-click > refactor > infer generic type arguments...

have @ documentation of eclipse's "infer generic type arguments" refactoring: http://help.eclipse.org/kepler/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/ref-menu-refactor.htm

also see previous stackoverflow question: how use "infer generic type arguments..." in eclipse


Comments