问题
I have some third party library Foo with class FooBar. I think that class FooBar is badly designed. I want to write my own MyBar as adapter pattern. Can I mark the original FooBar as @Deprecated
without modifying its code?
回答1:
@deprecated should be added to the source to flag the class/method as deprecated. So you cannot deprecate someone else's code.
However if you have a better alternative that you prefer to use in your project as a standard, then you can impose this standard in other ways, as a rule in checkstyle for instance.
回答2:
You cannot mark it as deprecated without compiling so will need the source
回答3:
As an alternative, use your IDE's "find references" function to find all places where your code uses the offending class. Or use "grep".
回答4:
Of course, one could change the class file adding the deprecated annotation to the class. (But I'm not proficient with the tools needed to do this.)
来源:https://stackoverflow.com/questions/5216689/mark-as-deprecated-third-party-class