| Author |
Cast from an Object to a primitive long
|
Natalie Kopple
Ranch Hand
Joined: May 06, 2003
Posts: 320
|
|
I posted a question before; but, that question was completely misleading. I feel sorry for that. Let me try to do it better.
|
 |
Richard Green
Ranch Hand
Joined: Aug 25, 2005
Posts: 536
|
|
|
return (long[])theUserIDList.toArray(new long[theUserIDList.size()]);
|
MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24054
|
|
Originally posted by Lynette Dawson: return (long[])theUserIDList.toArray(new long[theUserIDList.size()]);
Well... no. The argument to toArray() is an Object array, not a long[] or other primitive array type. As I think I told you earlier today: allocate your array of longs, assign each one, one at a time. You could do it with direct assignment in Java 5 due to autoboxing; otherwise, you'll have to call longValue() on your longs explicitly.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
Well... no. The argument to toArray() is an Object array, not a long[] or other primitive array type. As I think I told you earlier today: allocate your array of longs, assign each one, one at a time. You could do it with direct assignment in Java 5 due to autoboxing; otherwise, you'll have to call longValue() on your longs explicitly.
Incidentally as an excersise in redundancy, I just wrote a class of static utility method for just that purpose, although I'm sure there's a library out there that does this already.
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
 |
|
|
subject: Cast from an Object to a primitive long
|
|
|