When in IntelliJ you enter some code like this :
在IntelliJ中,您输入一些代码如下:
Runnable cronTask = new Runnable() {
@Override
public void run() {
// do something
}
};
IntelliJ will automatically suggest that this will be better when using a lambda expression. And you have the option to do an automatic conversion to
当使用lambda表达式时,IntelliJ会自动建议这会更好。您可以选择自动转换为
Runnable cronTask = () -> {
// do something
};
Is something like this possible in Eclipse ? Maybe with some kind of plugin ? I want Eclipse to give me warnings of where a lambda expression might be a better solution. And if possible also suggest the correct fix.
这样的东西在Eclipse中可能吗?也许有某种插件?我希望Eclipse能够告诉我lambda表达式可能是更好的解决方案。如果可能的话也建议正确的解决方案。
1 个解决方案
#1
3
To the best of my knowledge, there is no way to make Eclipse show compiler warnings where lambda expressions are a better alternative. Nevertheless, there is a nice feature that takes care of the automatic conversion you requested.
据我所知,没有办法让Eclipse显示编译器警告,其中lambda表达式是更好的选择。不过,有一个很好的功能可以处理您请求的自动转换。
Right-click on any project or Java file, and select Source -> Clean Up... In the window that appears, select Use custom profile, and click Configure... In the Code Style tab, enable Convert functional interface instances, and make sure Use lambda where possible is selected, as shown in the screenshot below:
右键单击任何项目或Java文件,然后选择Source - > Clean Up ...在出现的窗口中,选择Use custom profile,然后单击Configure ...在Code Style选项卡中,启用Convert functional interface instances,and确保选择使用lambda,如下面的屏幕截图所示:
Validate and run the clean up. This feature alongside the manual Quick assist suggested by Timothy Truckle in the comments will hopefully cover most of your needs.
验证并运行清理。此功能以及Timothy Truckle在评论中提出的手动快速助手将有望满足您的大部分需求。
#1
3
To the best of my knowledge, there is no way to make Eclipse show compiler warnings where lambda expressions are a better alternative. Nevertheless, there is a nice feature that takes care of the automatic conversion you requested.
据我所知,没有办法让Eclipse显示编译器警告,其中lambda表达式是更好的选择。不过,有一个很好的功能可以处理您请求的自动转换。
Right-click on any project or Java file, and select Source -> Clean Up... In the window that appears, select Use custom profile, and click Configure... In the Code Style tab, enable Convert functional interface instances, and make sure Use lambda where possible is selected, as shown in the screenshot below:
右键单击任何项目或Java文件,然后选择Source - > Clean Up ...在出现的窗口中,选择Use custom profile,然后单击Configure ...在Code Style选项卡中,启用Convert functional interface instances,and确保选择使用lambda,如下面的屏幕截图所示:
Validate and run the clean up. This feature alongside the manual Quick assist suggested by Timothy Truckle in the comments will hopefully cover most of your needs.
验证并运行清理。此功能以及Timothy Truckle在评论中提出的手动快速助手将有望满足您的大部分需求。