Call a class method within a map | SoloLearn: Learn to code for FREE!


Call a class method within a map

How would I approach telling the HashMap to store a method call within the same class it's stored in? My initial approach was to call HashMap like so: HashMap<String, sysCall> cmdList; It's used to quickly lookup the given input from the user, and call the appropriate method to complete their command. I figured this was more efficient than a large amount of nested if/else statements. Unless someone has a better solution, I'm all ears! Thanks in advance!

11/10/2017 3:40:20 PM


3 Answers

New Answer



You could also use a lambda expression instead of calling a method


That's a clever way of getting a class method, that might be a way. I'll read more in depth on it on the text about using that solution. Also, yes I could use lambda, but these methods already exist, and it'd be silly for me to create a 2nd identical one. Thanks for the response