Because when you declare the method, you say this:
static void insert_at_bottom(Stack st, int x)
Which means that
st
can contain any value: an
Object
, and you can;t automatically convert an
Object
to any other type.
Instead, tell the system what your stack contains, and it'll understand what you are doing:
static void insert_at_bottom(Stack<Integer> st, int x)
You will need to do the same to your
reverse
method as well.