I have the following classes:
interface Ivisitor{ @deduceStrategy("...") void visit(Icosmos c); } Visitor implements this interface:
class Visitor implements Ivisitor{ @deduceStrategy("...") public void visit(Icosmos c) { .... } } The dynamic proxy:
public class strategyLoader{ public static <T> T create(Class<T> clazz,Object wrap) { T object = (T) Proxy.newProxyInstance(strategyLoader.class.getClassLoader(), new Class[] { clazz },new Handler(wrap)); return object; } } Relevant portion of the handler class:
public class Handler implements InvocationHandler { Object obj; public Handler(Object obj) { this.obj = obj; } public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { if (m.isAnnotationPresent(deduceStrategy.class)) { Class[] parameterTypes = m.getParameterTypes(); if((parameterTypes.length==1)&&(**Icosmos.class.isInstance(parameterTypes[0])**)) { ........ } I need to load the appropriate strategy based on the exact type of Icosmos passed into Visitor.visit. However,the parameter[0] is never resolving to an instance of Icosmos. Would appreciate if someone showed me the way out. The client invokes visitor as:
Ivisitor visitor = strategyLoader.create(Ivisitor.class,Visitor.class.newInstance());