Java 9:Building Robust Modular Applications
上QQ阅读APP看书,第一时间看更新

Eliding depreciation warnings on import statements [JEP 211]

This is one of the more simplistic JEPs for Java 9. Quite often, when we compile our programs, we receive many warnings and errors. The compiler errors must be fixed as they are typically syntactical in nature. The warnings, on the other hand, should be reviewed and appropriately addressed. Some of the warning messages are ignored by developers.

This JEP provides slight relief in the number of warnings we receive. Specifically, depreciation warnings caused by import statements are no longer generated. Prior to Java 9, we could suppress deprecated warning messages with the following annotation:

    @SupressWarnings

Now, with Java 9, the compiler will suppress depreciated warnings if one or more of the following cases is true:

  • If the @Deprecated annotation is used
  • If the @SuppressWarnings annotation is used
  • If the use of the warning-generating code and the declaration are within the ancestor class
  • If the use of the warning-generating code is within an import statement

The fourth condition listed was an addition in Java 9.