6 December 2017

Java 9 @Deprecated

That is to say: Java 9 enhances Deprecated.

@Deprecated(forRemoval=true)

The @Deprecated annotation has a new parameter forRemoval (default: false).
If the parameter is true, the item will be removed in a future version, according to javadoc.
This used to be the meaning of Deprecated in the beginning (when it was still a javadoc tag), but Java never actually removed anything marked Deprecated AFAIK.
That is, until Java 9, where some items effectively got pruned, to avoid cyclic dependencies in the new module system (in java.beans.PropertyListener).
Oracle says that, for Java SE, the intend is that something marked with @Deprecated(forRemoval=true) in Java 10, will be gone in Java 11 (ouch).

Suppressing warnings

Deprecation warnings are also impacted.
You can surpress compiler deprecation warnings with @SuppressWarnings(“deprecation”) in your code.
This does not work for imports, but that is a bug that is (finally) solved in Java 9.
On the other hand, In Java 9 the @SuppressWarnings(“deprecation”) will not work for @Deprecatedor(forRemoval=true). And rightfully so, given that people suppress the warnings because they assume nothing is going away any time soon.
 In Java 9, to suppress forRemoval=true warnings, use  @SuppressWarnings(“removal”).
To suppress both forRemoval=false and forRemoval=true, use @SuppressWarnings("deprecation", “removal”).