3

I understand the Java @Deprecated annotation comes with fields since and forRemoval. However, this is not sufficient for developers to switch to the non-deprecated alternative(s) and therefore it is recommended to additionally put a Javadoc with the @deprecated flag and the link to the new method/class/interface to favor.

Why is the @Deprecated annotation not already providing such a most relevant field like useInstead, or inFavorOf (even allowing multiple values)?

It would definitely ease the transition and foster developers to put in the new methods/classes/interfaces to use instead - currently I have to draw dependency sources to get their Javadocs, and even then often times no alternative to the @deprecated method/class/interface is mentioned, so that I have to research what the developers of the original code already knew.

DaHoC
  • 314
  • 1
  • 4
  • 14
  • Probably because it's easier to read in the JavaDoc, than the Annotation itself. Plus The Compiler won't have any problems if the "useInstead" class doesn't exist in yet, whilst using JavaDoc – Z-100 Feb 06 '23 at 09:53
  • Let's say it's an explanation of three paragraphs, you really think reading that would be easier from a field in the annotation compared to from formatted documentation? – Stultuske Feb 06 '23 at 09:56
  • Also, it is important to realise that the `@deprecated` javadoc tag (introduced in Java 1.1, I think) precedes the existence of the `@Deprecated` annotation (Java 5). The `since` and `forRemoval` fields of the annotation where only introduced in Java 9. – Mark Rotteveel Feb 06 '23 at 10:08
  • 4
    When the `@Deprecated` annotation was introduced (in Java 5), it had no attributes at all. As someone once said [“*I’m often asked why the compiler does not implement this feature or that feature, and of course the answer is always the same: because no one implemented it. Features start off as unimplemented and only become implemented when people spend effort implementing them: no effort, no feature.*”](https://ericlippert.com/2012/03/09/why-not-automatically-infer-constraints/#:~:text=I%E2%80%99m%20often%20asked,no%20feature.) – Holger Feb 06 '23 at 10:17

0 Answers0