java - Call different methods depending on input parameters -


Please give me a suggestion and an example how can I apply this situation when I get to the consultants that come with the map Call on different methods. Public string main method (calculation of int) {If (count == 1) {myMethod} and if (count == 2) {myMethod2} return and if (calculation == 3) {MyMethod3}} public string myMethod1 () Return {..............} public string myMethod2 () {..............} public string myMethod3 () {..... .........}

The question that was raised in your comment It was mentioned in it:

  Maps & lt; Integer, callable & gt; Map = new hashmap & lt; & Gt; (); Map.put (1, new callable () {public object calls ()) throws an exception {code for 1 argument 1 return tap;}}); Map.put (2, new callable () {public object calls ()) throws an exception {code 2 return tap for logic;}}); Map.put (3, New Callable () {Public Object Call ()) throws an exception {Code 3 return blank for 1 argument;}});  

You can now use it as a

  map.get (count). Call ();  

Comments