List<String> rows = new ArrayList<String>();
18 June 2016
I know Eclipse Neon brings features in the Java editor that I will use almost every day. I have already blogged about Bug 476304. It will be a pleasure to be able to navigate to inner classes correctly.
Today I want to write about the clean-Up to remove redundant type arguments feature. This is something I was looking for at the beginning of 2015.
Since Java 7 you can use the Diamond operator. The code line presented in Listing 1 (Java 6) can be written as in Listing 2 (Java 7).
List<String> rows = new ArrayList<String>();
List<String> rows = new ArrayList<>();
With Eclipse Mars (and probably before) you could already let the compiler warn you about Redundant type arguments. The setting is under Preferences → Java → Compiler → Errors/Warnings in the tree. And in the list: Generic Types → Redundant type arguments (1.7 or higher) as presented in Figure 1.
With this setting enabled, it was possible to Quick-Fix all the code locations that were not using the diamond operator (see Figure 2).
This is a lot of CTRL+1 for an operation that does not require any manual intervention. If the team as decided to use the diamond notation, it should be used everywhere. This belongs to coding guidelines, exactly as code format.
With Eclipse Neon a new clean-up action makes this possible! You can configure Eclipse to remove redundant type arguments when you save your Java files. Open the preference page Java → Editor → Save actions. Check the Checkbox "Additional actions" and click on the Configure… button. Switch to the "Unecessary Code" Tab and enable "Remove redundant type arguments (1.7 or higher)"
Eclipse neon is coming next wednesday. Stay tuned!