Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the clearest way to deprecate a package in Java?

I'm working on a new codebase and migrating the system to a new framework.

There are a number of packages that I would like to deprecate, just to make it very clear to other developers that everything inside this package should not be used anymore for new development.

What is the best way to indicate that an entire package has been deprecated?

like image 861
Daniel Alexiuc Avatar asked Feb 22 '11 05:02

Daniel Alexiuc


People also ask

What is deprecated method?

Similarly, when a class or method is deprecated, it means that the class or method is no longer considered important. It is so unimportant, in fact, that it should no longer be used at all, as it might well cease to exist in the future. The need for deprecation comes about because as a class evolves, its API changes.

Do deprecated methods still work in Java?

You can still use deprecated code without performance being changed, but the whole point of deprecating a method/class is to let users know there's now a better way of using it, and that in a future release the deprecated code is likely to be removed.

How do you deprecate in Java?

How to Deprecate? We use the @Deprecated annotation to deprecate a method, class, or field, and the @deprecated Javadoc tag in the comment section to inform the developer about the reason for deprecation and what can be used in its place.


2 Answers

I had to do this recently and used the package-info.java file to deprecate the package.

http://www.intertech.com/Blog/whats-package-info-java-for/

Add a package-info.java file to your package with only the package declaration:

/**  * @deprecated As of release 2.0, replaced by {@link com.acme.new.package}  */ @Deprecated package com.acme.old.package; 

In Eclipse, all places where the user imports a class from this package will be underlined with a deprecation warning.

like image 200
muymoo Avatar answered Sep 19 '22 00:09

muymoo


You said it yourself: You want to deprecate everything that's inside a package, not the package itself. The package is nothing but a namespace and deprecating a namespace would have a different meaning - like don't use this namespace anymore. Like don't add any new items to that namespace.

In your case, I suggest you deprecate each public method (and field) of each class that shouldn't be used anymore. This becomes visible in modern IDE's and developers are warned when they want to use the old classes and methods. And you can look through your code and refactor it step by step to eliminate dependencies of those classes and methods.

like image 34
Andreas Dolk Avatar answered Sep 18 '22 00:09

Andreas Dolk