Java格式下的格式是某种约定吗?我个人发现它比第二个例子更难阅读.我一个人在这里吗?在选择Source - > Format时,有没有办法在NetBeans中进行这样的自定义格式化?
public boolean handleEvent(Event e) {
if (e.target == quit) System.exit(0);
else if (e.target == parent) {
// Code here
// Bug workaround
}
catch (IOException ex) { infoarea.setText("I/O Error"); }
return true;
}
Run Code Online (Sandbox Code Playgroud)
(第二个例子)
public boolean handleEvent(Event e)
{
if (e.target == quit) System.exit(0);
else if (e.target == parent)
{
// Code here
// Bug workaround
}
catch (IOException ex) { infoarea.setText("I/O Error"); }
return true;
}
Run Code Online (Sandbox Code Playgroud)
维基百科有一篇关于缩进风格的文章.Oracle已经设置了Java编码约定和样式指南PDF.确实这是一个品味问题,但是特定于Java的指导原则使得所有Java代码都可以被其他Java开发人员快速,易懂地理解和维护.我讨厌在Java代码中看到C#样式,但反过来说,我也讨厌在C#代码中看到Java风格.对Java代码使用Java样式,对C#代码使用C#样式.它让每个人都清楚一切.
你的例子没有编译,但假设确实没有try,这就是人们如何用干净的Java方式做到的:
public boolean handleEvent(Event e) {
if (e.target == quit) {
System.exit(0);
} else if (e.target == parent) {
// Code here
// Bug workaround
} catch (IOException ex) {
infoarea.setText("I/O Error");
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
你呈现的第一种风格看起来很像横幅风格,第二种风格很像GNU风格(有点类似于Allman/C#风格.
| 归档时间: |
|
| 查看次数: |
2207 次 |
| 最近记录: |