judas123

Greenhorn
+ Follow
since Mar 29, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by judas123

I have similar problem.

Object[] myArray;

if(...){myArray={3,4,5};}
else(....){myArray={'a','b','c'};}

of course i can create new variables and cast to them;

Integer[] arrayInt; /// arrayInt=(Integer[])myArray;
Character[] arrayChar; ////............

but the problem is i wanna use one variable name in code after that. Only myArray!!!
1. Is there a way to change the type of given variable?
2. Or how to find variable type and use it for dynamical declaration?
for instance
<type of any variable> c= new <type constructor>

Probably getClass() is the answer but, how to use it?
[ March 29, 2008: Message edited by: judas123 ]
15 years ago