Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

java - Possible to mark my class/method as deprecated based on the JRE/JVM version?

Ten years ago I created, and have maintained, some commons/library jar files of helper classes specifically for cryptography in Java 8. Our organizations are FINALLY starting to update to Java 11 LTS, in which similar functionality has been added natively.

These commons are used across many groups in my company but as individual groups upgrade to Java 11+ JRE/JVMs, I would like to encourage them to use the new native classes vs. my libraries.

Is there a way to annotate/Javadoc-tag my classes/methods such that they only warn as deprecated when built with a Java 11+ JRE/JVM?

My classes still work perfectly fine in Java 11+, but I'd really like to encourage using the now native classes/methods. If depreciation is not the way to go, are there other annotation/Javadoc methods to discourage use via warning when used beyond a specific version of JRE/JVM?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is no way to do that out of the box. I suggest you just include the explanation in the JavaDoc text.

Deprecation is overkill because it sounds like you have no intention of actually removing it. You just want to encourage users targeting a later version to use something else.

You could always write your own annotation and annotation processor, of course.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...