+ 2

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!

10th Nov 2017, 3:40 PM
Sapphire
3 Answers
+ 8
You could also use a lambda expression instead of calling a method
10th Nov 2017, 4:14 PM
qwerty
qwerty - avatar
+ 2
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
10th Nov 2017, 4:24 PM
Sapphire