I have a seemingly simple question that I have not been able to find a solution in about a week of searching, so I thought I'd ask. I want to take an array value, say anArray[1]
and set it equal to a variable in another class... otherClass.variableOne
This is easy to do, but I want to be able to use a variable for the name of the class i want the variable from. So instead of "otherClass.variableOne" i want something like:
String classVar = "otherClass";
anArray[1]=classVar.variableOne;
I'm not sure whether i need to set classVar equal to something like... className(otherClass) or something like that. I am quite new to Java and I'm having great difficulty.
I know this seems dumb but it is necessary for what I want to do. I have looked into reflection but it doesn't seem to able to do what I need. Essentially my question is:
String classVar = "otherClass";
anArray[1]=classVar.variableOne
How do i make something like that work where classVar is a variable that refers to a class that contains the public static int variableOne?
Please excuse limited programming experience. Any help is greatly appreciated. Thanks in advance.