I want to create a proxy for a class instead of an interface. There are answers describing use of cglib or Javassist for this purpose (e.g. https://stackoverflow.com/a/4449998/), but I've run into a wrinkle, as the class I am interested in proxying doesn't have a no-argument constructor, so Enhancer.create()
throws an exception. Looking at Javassist ProxyFactory
javadoc, it needs constructor arguments as well.
The obvious workaround is finding constructor argument types by reflection and passing an array of nulls/0/etc. but this won't work if the constructor throws an exception.
Are there better alternatives (perhaps using some other library)?