Can Eclipse auto-generate an interface of a 3rd party library class?

纵然是瞬间 提交于 2019-12-10 02:49:59

问题


I'm working with Apache's FTPClient class in the Apache commons net library. Sadly it doesn't implement an interface for most of the functionality which makes testing classes which use it tricky. So, I thought I'd create my own class which wrappers this one and implements an interface. Anyway that's the background. My question is, is it possible in Eclipse to generate an Interface (similiar to Refactor->Extract Interface) but for 3rd party code sitting in a jar file?

Just to clarify, I'm not looking for FTPClient to now implement the new interface, but to create an interface which mimics the same public API as FTPClient. I can then create my own class which implements this interface and wrappers the FTPClient.


回答1:


Hm. Why not start with an empty class, like

class MyWrapper {

    private Referent client;
}

Then, I'd do "Source -> Generate Delegate Methods", populating the empty class with delegating calls to the underlying original object as I need them. From that class, you can now "Refactor -> Extract interface"... As you need the wrapper for production anyway, this will solve both problems (wrapper generation + interface generation) at once.



来源:https://stackoverflow.com/questions/6357784/can-eclipse-auto-generate-an-interface-of-a-3rd-party-library-class

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