Mark as deprecated third party class

故事扮演 提交于 2020-05-13 04:10:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!