How to get content assist for "for loop" anywhere in Eclipse?

Viewed 12759

In Eclipse, after a line like this:

List list = new ArrayList();

Typing "for" just beneath, and followed by "ctrl-space" (by default), will bring several options that can help completing this "for loop": assist

But if the variable "list" is declared far from here (e.g. as a class field) which may not be directly inferred from this context, or there are many Lists declared,then the assistance doesn't work well:

not work @@ split line ---

enter image description here

In some cases, Eclipse can assist, but just don't work for member variable. E.g. manually type "another" and ENTER after the ":" didn't persuade Eclipse to guess about it....

(P.S. workable case:

Auto guessed

auto guessed

Entered wanted name, and ENTER, works great

entered wanted name, and ENTER, works great)

Does anyone have any tip to make this assistance work under such scenarios?

4 Answers

Years later, if you enter the name of the field/variable you can press Quick Fix (⌘+1) and in the quick fix menu you can choose different types of for-loops for the collection or array. Automatically generate for-loop using Quick Fix

Related