Link to home
Start Free TrialLog in
Avatar of Ricosta Collins
Ricosta Collins

asked on

dynamic naming in java - using a variable name to create an instance

Dynamically naming new java object.

//An item from a list is selected and stored in the variable departure as a string.

String departure = (String) listOrigin.getSelectedValue();

I want to then use this variable to create an instance in order to access object properties/data.

departure accessData = new departure

Data is stored in a class with the same name as the departure if that makes sense, but in a different package, hence why i need to create an instance. I need to access the data in that departure class.

accessData.get+departure+() //method can then be called so data can be returned

Any ideas ?
Avatar of dpearson

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dpearson

Asked and answered.