jeudi 9 avril 2015

Is the instance of Method class in java is global unique

In the whole jvm run life, is the Method class instance always unique? for example, I have a class which implements InvocationHandler. In method invoke, which has a Method parameter. I know all methods that i can handle, and I want to use different strategy to handle different method. So I build a strategy map like Map. codes like:



@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Strategy strategy = strategyMap.get(method);
Method realMethod = strategy.getCorrespondingMethod();
return realMethod.invoke(this, args);
}


The question is IF i use this strategy, the Method object MUST be global unique in the whole JVM running life. Otherwise, i cannot find the correct strategy.


So, Is the instance of Method class in java is global unique.


Question 2: How about the efficient of Method:toGenericString(), i the use method object cannot accomplish this job, i think i can use method generic string.


Thank you.






Aucun commentaire:

Enregistrer un commentaire