For better readability of a lengthy method, I’d like to replace a repeatedly used block of code (only assignments) with a method. I therefore selected the block of code and ran Eclipse’s Extract Method feature, but that failed with this error:
Ambiguous return value: Selected block containsmore than one assignment to local variables. Affacted variables are:
int foo double[] bar
How can I fix this? It should be a simple void method doing a couple of assignments, I’m not sure what Eclipse (3.6.2) complains about.
Eclipse wants all variables that are used as arguments and return one or no variable that was modified within the extracted block.
You issue is a construct like
Since both variables (foo,bar) are needed in further statements they can’t be returned as one value.
You could return a class containing foo and bar.
Declareing them as member variables works
as well as this: