Eclipse Tip: Surround With



A few times, after I code a block of code, I want to execute it only if a condition is true. For example I want to perform some operations on an object person but only if it is not null (obviously). Eclipse has a quick fix to surround this block of code with an if statement. Just select the block of code and press Crtl + 1 or choose Edit > Quick Fix. Eclipse gives you a list of options as shown above. You can choose “Surround with ‘if’ (if statement)” and the code is surrounded by an if statement. You can fill up the condition and you are done. 


You can also use the above trick to get other surround statements listed above.

Vasanth Dharmaraj is a Java Architect currently working for Western Union living in the Bay Area. He is interested in programming, gadgets, formula one... You can follow him on Twitter.

Posted in Eclipse, Java

Ads By Google