A JBoss Project
Red Hat

Posts tagged with 'tip'

When you have have typed collections in your code like:

public void process(List<Product> products) {
  List<Customer> customers = getCustomers();
  // cursor here
}

Most know that you can use the foreach template via normal content assist to quickly generate code like this:

public void process(List<Product> products) {
  List<Customer> customers = getCustomers();
  for(Customer c : customers) {
    // cursor here
  }
}

But the foreach template will always choose the nearest collection, making it impossible to use with for example the products parameter in the above example.

The solution is to use the 'enhanced for loop' Quick Fix.

It is available when you have type the name of the collection and use the Ctrl+1 (Cmd+1 if on OS X) shortcut.

To illustrate it, here is a small video of it in Eclipse.

Hope you enjoyed this little tip!

Thanks to Xavier Coulon for asking the question and giving the idea for this Tip blog, and thanks to Markus Keller (JDT UI lead) for reminding me about the Quick Fix solution.

Have fun,
Max Rydahl Andersen
@maxandersen

JBoss Tools 4.29.0.Final for Eclipse 2023-09

by Stéphane Bouchet on Nov 02, 2023.

JBoss Tools 4.28.0.Final for Eclipse 2023-06

by Stéphane Bouchet on Jul 03, 2023.

JBoss Tools for Eclipse 2023-06M2

by Stéphane Bouchet on Jun 05, 2023.

JBoss Tools 4.27.0.Final for Eclipse 2023-03

by Stéphane Bouchet on Apr 07, 2023.

JBoss Tools for Eclipse 2023-03M3

by Stéphane Bouchet on Mar 10, 2023.

Looking for older posts ? See the Archived entries.
back to top