For example, let's say I wanted to "extract" String[] fruits = {"Pear", "Banana", "Apple"}; into three separate variables, for example:
for (int i=0; i != fruits.length; ++i) { // of course there no eval in Java eval("String fruit + i = " + fruits[i] + ";"); } // ie: code that creates something equivalent to the following declarations: String fruit0 = "Pear"; String fruit1 = "Banana"; String fruit2 = "Apple";
How could I do this, ignoring "Why the hell do you want to do this?" the question is that you may be asked to ask me.
Similar questions were asked many times before, but the real answer was never given, because the OP really needs to use a different approach. This is great, but is it even possible?
I looked at the reflection, and it does not seem that there are any methods that would even allow me to add additional instances to the instance, not to mention the dynamic creation of locales.
source share