I have the following code that works for creating a Proxy instance for an interface type backed by an InvocationHandler
implementation, however when I use a concrete class type it doesn't work and this is well known and documented in Proxy.newProxyInstance:
// NOTE: does not work because SomeConcreteClass is not an interface type
final ClassLoader myClassLoader = SomeConcreteClass.getClassLoader();
SomeConcreteClass myProxy = (SomeConcreteClass) Proxy.newProxyInstance(myClassLoader, new Class[] {
SomeConcreteClass.class }, new InvocationHandler() { /* TODO */ });
However, if I recall correctly I have seen this use-case work in some mock frameworks where it is possible to mock a concrete class type e.g. EasyMock. Before checking up their source code can anyone indicate what needs to be done to proxy also concrete class types and not only interfaces?