reference type to primitive type conversion

Hello,

How can i convert an object of reference type to a primitive type (long type for example)?

I have a long value:

Long pc =2;

I add it to a Stack :stack,

stack.add(pc);

When I will extract the pc value from the stack,

long pc =stack.pop();

This is incompatible type, how can I convert an object to a long type?

Please anyone help me.

Regards.

[448 byte] By [asmainfa] at [2007-11-27 4:45:58]
# 1
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Long.html#longValue()or define your stack as a Stack<Long>
ejpa at 2007-7-12 9:58:28 > top of Java-index,Core,Core APIs...
# 2

This maybe help

Since JDK 5.0 we can use Autoboxing features

long pc = 2;

long new_pc;

Stack s = new Stack();

s.add(pc);

new_pc = (Long)s.pop();

I'm Thai , Sorry for my English.

einstein2_tha at 2007-7-12 9:58:28 > top of Java-index,Core,Core APIs...
# 3
He already is using Autoboxing features. Otherwise Long pc = 2 wouldn't even compile.
ejpa at 2007-7-12 9:58:28 > top of Java-index,Core,Core APIs...