“Surround with”-template in Eclipse: foreach

后端 未结 4 786
借酒劲吻你
借酒劲吻你 2021-02-04 14:58

I am new to Eclipse which I use primarily for Java. I have previously used IntelliJ Idea in which it is possible to select a variable which extends Iteratable (Collection, List

4条回答
  •  离开以前
    2021-02-04 16:04

    I typically create code like this by following these steps:

    Call the function and use Ctrl-1 to create a local variable holding the return value:

    List list = functionWhichReturnsList()
    

    Type fore[Ctrl-space] to insert the for loop (since eclipse usually chooses the closest iterable when constructing the loop):

    List list = functionWhichReturnsList()
    
    for (TypeOfItemsInList item : list) {
    }
    

    Inline the local variable by putting the cursor on the list variable and typing Alt+Shift+I:

    for (TypeOfItemsInList item : functionWhichReturnsList()) {
    }
    

    It's not optimal, but it works.

提交回复
热议问题