有没有一种方法可以使用实时模板为现有变量快速生成foreach? [英] Is there a way to quickly generate a foreach for an existing variable using live templates?
本文介绍了有没有一种方法可以使用实时模板为现有变量快速生成foreach?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码段:
Set<Company> companiesByUserName = companyUserService.getCompaniesByUserName(username);
使用IntelliJ实时模板,我知道我可以键入"itco",它将为我生成以下内容:
Using IntelliJ live templates, I know I can type "itco" and it will generate the following for me:
for (Iterator<Company> iterator = companiesByUserName.iterator(); iterator.hasNext(); ) {
Company next = iterator.next();
}
但是,如何使用'companiesByUserName'变量自动创建foreach?所以我想让它自动生成:
However, how can I automatically create a foreach with the 'companiesByUserName' variable instead? So I want it to generate this automatically:
for (Company company: companiesByUserName) {
}
因为foreach在for循环中遍历集合非常干净,所以我通常改用这些,因此在可能的情况下希望自动生成它们.
Because the foreach is a lot cleaner that iterating through the collection in a for loop, I generally use those instead, so would like to auto generate them if possible.
推荐答案
没关系,找到了解决方法.只需键入"iter",然后按Enter.
Nevermind, found out how to do it. Just type "iter" and press enter.
这篇关于有没有一种方法可以使用实时模板为现有变量快速生成foreach?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文