Hi everyone,
I got trouble about storing method in HashMap. I got the example but there is no parameter in method, You can see the code below
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author user */ public class PracticeMap { public static void main(String[] args) { Map<String, Method> methodMap = new HashMap<String, Method>(); try { methodMap.put("help", PracticeMap.class.getMethod("showHelp")); methodMap.get("help").invoke(null); } catch (NoSuchMethodException ex) { Logger.getLogger(PracticeMap.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(PracticeMap.class.getName()).log(Level.SEVERE, null, ex); }catch (IllegalAccessException ex) { Logger.getLogger(PracticeMap.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalArgumentException ex) { Logger.getLogger(PracticeMap.class.getName()).log(Level.SEVERE, null, ex); } catch (InvocationTargetException ex) { Logger.getLogger(PracticeMap.class.getName()).log(Level.SEVERE, null, ex); } } public static void showHelp() { System.out.println("Help me!!"); } }
I want to put parameter in showHelp method. But I don't how to that.
Please share me information if you already know