Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save action in Eclipse IDE to convert the java code to the diamond notation

If you have a java version >= 1.7 you can use the diamond notation.

Instead of:

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. (Maybe this was already the case with Eclipse Luna version. I did not check):

Java Code

This is due to this configuration:

Preferences > Java > Compiler > Errors/Warnings in the tree. In the list: Generic Types > Redundant type arguments (1.7 or higher).

Errors/Warnings preference page

This is set to ERROR. I can of course configure it to IGNORE to remove the error.

I am searching for another solution. Eclipse has the notion of “Additional actions”. I am looking for an action that would rewrite the code to the diamond notation.

Does this action already exist? How can I configure it?

Related question:

  • Convert existing generics to diamond syntax (but this is in NetBeans).
like image 957
Jmini Avatar asked Jul 10 '26 14:07

Jmini


1 Answers

Unfortunately this is not possible out of the box. You would need to write your own plugin and implement the ICleanUp interface.

If you wish to create your own plugin, details on how to create a cleanup and save action can be found here: Contributing a clean up and a save action using the clean up extension point

like image 50
DB5 Avatar answered Jul 12 '26 03:07

DB5



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!