The Scenario is:
Object anObj="7";
Object anotherObject="7.77";
Class aClass=Class.forName("java.lang.Integer");
Class anotherClass=Class.forName("java.lang.Double");
I want to typecast anObj to aClass-type and anotherObject to anotherClass-type.
The values for Class variables aClass and anotherClass may vary, so i dont want them to be casted using the parseXXX() methods…
I tried using aClass.cast(anObj); but it throws InstantiationException
Can anybody help me?
Thanks in advance.
ArK.!
Before casting them to aClass and anotherClass, you need to cast anObj and anotherObject to respective classes