Issues on cast Object to Integer or String
<p>I have to implement an interface IExecutable for a console menu application.The method that i am implementing is: <strong>Object execute(Object o);</strong> So i display the menu. I read from the console an menu option that could be an Integer or a String. On execution i have this error : 
<strong>java.lang.String cannot be cast to java.lang.Integer</strong>
The question is which is the best way make that conversion.</p>

<p>ConsoleMenu.java</p>

<pre><code>public Object execute(Object o) {
        show();
        o = read();
        try{
            int choice = Integer.parseInt((String) o); // error on this line
            IExecutable menuOption = getMenuOptions(choice);
            if(menuOption != null){
                o = menuOption.execute(o);
                return o;
            }
              } catch(Exception e){
            System.out.println("Invalid option"+ e.getMessage());       
        }

        return null;
    }

private static IExecutable getMenuOptions(int i){
    for(MenuOptions option :  options){
        if(option.getKey() == i &amp;&amp; option.getIsActive()){
            return option;

        }
    }
    return null;
}

public static Object read(){
        String option = null;
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        try {
                option = buffer.readLine();
                return option;

            } 
        catch (IOException e) {
            System.out.println("IOException " +e.getMessage());
        }
        return null;
    }
</code></pre>

<p>Main.java</p>

<pre><code>public class Main {


    public static void main(String[] args) {
        Integer i = new Integer(1);
        ConsoleMenu menu = new ConsoleMenu("MATH OPERATIONS");
        menu.addMenuOption(new SubOption());
        menu.addMenuOption(new AddOption());
        i = (Integer) menu.execute(i);

    }

}
</code></pre>
