+ 1

How can i cast String to ObjectName

Hi Geeks I have 10 instances of class B, B b1 ,b2,b3,b4 etc ; i would like to excute them inside a loop : String s = "b"; B r ; int i = 0; while(i<10){ i++; r = (B) s + i;// i want to change thid valu to "B" class , but it didnt work with me , plz help if u can r.getClassName(); }

3rd Mar 2020, 7:45 AM
Nakamatori
Nakamatori - avatar
2 Answers
+ 2
I assume an array of B instances was not an option?
3rd Mar 2020, 7:57 AM
Ipang
+ 1
Can you share your code? According to above code snippet, while loop is Infinite.. And to cast, both must be compatible each other....
3rd Mar 2020, 8:38 AM
Jayakrishna 🇼🇳