I am using Proxy Pattern in Java (InvocationHandler), to implement a lock manager for a remote object, in the proxy class (which implements InvocationHandler). I am calling the remote object (here : flighRMConnection) :
if (method.getName().toLowerCase().contains("query")){
lm.Lock(Thread.currentThread(), READ);
} else {
lm.Lock(Thread.currentThread(), WRITE)
}
method.invoke(flightRMConnection, args);
How can I check the value returned by the invocation?(there might be different types of results)
Thanks , Arian
Well, the static return type of
invokeis naturallyObject. If you want to determine the dynamic type of an instance returned by the invocation, you can callgetClass()on it to get theClassobject representing its type.If you need to inspect its contents, you can do further reflection using the
Class(seegetDeclaredFields(), etc.). If there’s a known class or interface the object might extend, you could also check that withinstanceofand then cast it.Oh and don’t forget to make sure the returned object isn’t
nullbefore you call anything on it.