我有以下课程:
interface Ivisitor{
@deduceStrategy("...")
void visit(Icosmos c);
}
访问者实现了这个接口:
class Visitor implements Ivisitor{
@deduceStrategy("...")
public void visit(Icosmos c)
{
....
}
}
动态代理:
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;
}
}
处理程序类的相关部分:
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])**))
{
........
}
我需要根据传递给 Visitor.visit 的 Icosmos 的确切类型加载适当的策略。但是,参数 [0] 永远不会解析为 Icosmos 的实例。如果有人告诉我出路,将不胜感激。客户端调用访问者为:
Ivisitor visitor = strategyLoader.create(Ivisitor.class,Visitor.class.newInstance());