in java deprecation java 9 ~ read.
@Deprecated annotation in Java 9

@Deprecated annotation in Java 9

It seems weird to me that after an only little amount of research around new @Deprecated annotation (appeared to be the very small thing) I found surprisingly many discussions, criticism, and articles about the resulting change.

It seems like a baby step toward the effective deprecation in Java, and I would like to express my opinion on that. For me, the change is welcome, and it’s better than in previous version(s) of Java. With forRemoval() and since() methods inside, you are in the bigger press to avoid using deprecated stuff than without it.

My two points which are most important:

  • Finally we have a possibility to build tools around forRemoval() and since() to keep the codebase clean.

    • What I mean is mainly the build tools. The warning can (and actually in the vast majority of occasions is) be easily overlooked, and no action till the end of application life is performed on it. So compile time warning not enough to enforce clean codebase. Replacing the compilation warning with the failing build, when there is deprecated stuff even in the version where it was intended for removal, can easily bring the replacement stuff onto the surface to handle.

    • The second group of tools are IDEs and their ability to warn us about (or avoid using) the deprecated stuff more properly.

  • The second one is backward compatibility as always in Java - both new methods inside annotation are optional, so it’s no problem to accommodate new approach incrementally.

Another valuable statements:

  • No more deprecation warnings when you are importing deprecated type - not need to suppress this warning.

  • Deprecation of the whole package through is still working.

  • Presence JavaDoc tag @deprecated can be checked by Checkstyle for methods/classes which are marked with @Deprecated annotation.

  • SuppressWarnings(“deprecated”) still works.

  • Value of the since() is the string, so it gives the flexibility to include any desired version into it.

comments powered by Disqus