示例
//非垂直对齐
int[] myArray = { 1, 2, 3, 4, 5, 6 };
int theInt = 1;
String someString = "Hello";
double aDouble = 3.0;
- 1
- 2
- 3
- 4
- 5
//垂直对齐
int[] myArray = { 1, 2, 3, 4, 5, 6 };
int theInt = 1;
String someString = "Hello";
double aDouble = 3.0;
- 1
- 2
- 3
- 4
- 5
说明
代码垂直对齐的方式看起来很舒服,尤其是在变量多的情况下。但是Eclipse默认的是非垂直对齐的方式。
这篇文章进行了详细说明:为什么我要垂直对齐代码
设置
Window –> Preferences –> java –> Code Style –> Formatter
建议以默认设置为基础新建,勾选”Indentation”选项卡中的“Align fields in columns”