Save Activity in Eclipse IDE to convert java code to diamond notation
If you have java version> = 1.7 you can use diamond notation.
Instead:
List<String> rows = new ArrayList<String>();
You can write:
List<String> rows = new ArrayList<>();
With Eclipse Mars-M4, I have errors when I use the first construct. (It may have been with the Eclipse Luna version already. I haven't tested it):
It has to do with this configuration:
Preferences> Java> Compiler> Errors / Warnings in the tree. In the list: General Types> Redundant Type Arguments (1.7 or higher).
The value is set to ERROR. I can of course set it to IGNORE to remove the error.
I am looking for another solution. Eclipse has a concept called Additional Actions. I am looking for an action that would rewrite the code to diamond notation.
Does this action already exist? How do I set it up?
Similar questions:
- Convert existing generics to diamond syntax (but that's in NetBeans).
source to share
With Eclipse Neon, simply select Remove Redundant Type Arguments (1.7 or higher) from the Optional Code tab in the Advanced Save Operations windows (or in the Edit Cleanup - up Profile).
Read more in this blog post: Eclipse Neon: Diamond Notation as a Cleanup Action
source to share
Unfortunately, this is not possible out of the box. You will need to write your own plugin and implement the interface ICleanUp
.
If you want to create your own plugin, details on how to create a cleanup and save operation can be found here: Promoting cleanup and saving using the cleanup extension point
source to share
Looks like there is a ticket for targeting eclipse 4.6 https://bugs.eclipse.org/bugs/show_bug.cgi?id=434788
source to share