PDA

View Full Version : Convert Long to int?


Peltito
07-25-2003, 07:27 PM
long myLong = 2;
int myInt = myLong.intValue();

Note: myLong.intValue() doesn't work because it says an object type is required but a long is found...? This function is straight out of the Long listing in the 1.3.1 api. What am I doing wrong? Thanks for the help!

jamessan
07-25-2003, 09:57 PM
Originally posted by Peltito
long myLong = 2;
int myInt = myLong.intValue();long isn't a class. It's a primitive type. Long is a class. Notice the case difference. ;)

MJPhill
07-27-2003, 10:33 PM
Did you try type casting?

long myLong = 2;
int myInt = (int)myLong;