J
jtl.zheng
I have write a stack which have interfaces:
------- public void push(Object o);
------- public Object pop();
then I can push any type class object into the stack
and when I pop() one element I can use:
------- Object o=pop();
------- o.getClass();
to determine this element o belong to what class
(eg. if it's String it return "class java.lang.String")
my question is when I know this o is a String Object
how can I use its String interface
something like:
------- Object o=pop();
------- String s=o; // can't compiled here
// java.lang.Object, required:
java.lang.String
------- System.out.println(s.charAt(n)); // use the String
interface
I know this o is point to a String object
how can I use this o's String interface (to get something like
o.charAt(n)) ?
Thank you very much in advance
------- public void push(Object o);
------- public Object pop();
then I can push any type class object into the stack
and when I pop() one element I can use:
------- Object o=pop();
------- o.getClass();
to determine this element o belong to what class
(eg. if it's String it return "class java.lang.String")
my question is when I know this o is a String Object
how can I use its String interface
something like:
------- Object o=pop();
------- String s=o; // can't compiled here
// java.lang.Object, required:
java.lang.String
------- System.out.println(s.charAt(n)); // use the String
interface
I know this o is point to a String object
how can I use this o's String interface (to get something like
o.charAt(n)) ?
Thank you very much in advance