0

Okay so I have a function that looks like this:

public void createMap(String mapName){
ArrayList<Point> Positions = new ArrayList<Point>();
Positions = Maps.map1;
...
}

where Maps is another class, and map1 is a method in that class that returns an ArrayList of points.
What I want to do is make it so that instead of writing Positions = Maps.map1, I want to dynamically call the methods in Maps based on the value of the string mapName. How would I go abouts doing this?

3
Contributors
2
Replies
19
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

you can enclose method with with if-else condition or switch case condition(Note:- java 7 supports string in switch case.) and depending on calue call methods

1

Depends on the methods - do you mean different methods for one map (in which case see IIM's post), or that there are multiple maps each with its own implementation of the same method signature (in which case build a java.util.Map<String, Maps> to hold the name as key and a Maps instance as value then use the Map methods to get the instance by name.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.