这篇文章引自MIT公开课 6.005 — Software Construction on MIT OpenCourseWare, 链接为 https://ocw.mit.edu/ans7870/6/6.005/s16/getting-started/
1 Open Eclipse preferences.
- Windows & Linux : go to Window → Preferences .
- OS X : go to Eclipse → Preferences .
2 Make sure Eclipse is configured to use Java 8
- In preferences, go to Java → Installed JREs . Ensure that “Java SE 8” or “1.8.0_71” is the only one checked. If it’s not listed, click Search.
- Go to Java → Compiler and set “Compiler compliance level” to 1.8. Click OK and Yes on any prompts.
3 Make sure assertions are always on .
Assertions are a great tool for keeping your code safe from bugs, but Java has them off by default.
- In preferences, go to Java → Installed JREs . Click “Java SE 8”, click “Edit…”, and in the “Default VM arguments” box enter: -ea (which stands for enable assertions ).
4 Tab policy .
Configure your editor to use spaces instead of tabs, so your code looks the same in all editors regardless of how that editor displays tab characters.
- In preferences, go to Java → Code Style → Formatter . Click the “Edit…” button next to the active profile.
- In the new window, change the Tab policy to “Spaces only.” Keep the Indentation size and Tab size at 4. To save your changes, enter a new “Profile name” at the top of the window and click OK.