Java 7. @SafeVarargs

Java 7 provides a way to remove a compiler warning about generics vararg invocation. With Java 7 you can annotate your vararg method with SafeVararg annotation and your clients won’t get these nasty warnings any more. IntelliJ IDEA 10.5 will help you to perform this migration. It will find for you all the places where @SafeVarargs annotation is applicable and suggest you to add this annotation. Of course, it will also check if existing @SafeVarargs annotations are applicable.

Suppose you have annotated your method with @SafeVararg but already have suppressions for unchecked warning in client’s code:

Since its version 6 IntelliJ IDEA contains an inspection to find redundant suppressions (available in batch mode only). Now you can use it to remove all suppressions which are garbage in your code. It will carefully check that these unchecked warnings were caused by generics vararg invocation and suggest you to remove all such suppressions. Simply run the ‘Redundant Suppression’ inspection (Ctrl-Alt-Shift-I).

All you need to do is to install Java 7 and setup language level to 7.

Download IntelliJ IDEA 10.5 EAP, try the new described features and let us know what you think.

This entry was posted in New Features and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">