I need the help. How I do dynamic casting using reflection ? I must to pass only the class name.
My code is it:
... Class classe = null; // father of TransactionProcessor Module md = null; Method method = null; try{ classe = Class.forName(classname); // getInstnce is the SingleTon class and return TransactionProcessor type method = classe.getMethod("getInstance", null); //md = ( TransactionProcessor ) method.invoke(null,null); //I CANT DO IT because it is a code generic. md = ( ??? ) method.invoke(null,null); md.run(); }catch(){}; I know that I can get the type of return using: method.getReturnType().getName(); but I can do the dynamica casting ? Thanks
Hello Fernanda, Welcome to JavaRanch. Please do not cross post topics. Choose one forum per topic. Thank you for your cooperations. Closing this. Please respond here.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
This tiny ad is wafer thin:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth