This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Cast from an Object to a primitive long Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Cast from an Object to a primitive long" Watch "Cast from an Object to a primitive long" New topic
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
    
  13

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cast from an Object to a primitive long
 
Similar Threads
Simple ArrayList conundrum?
HF suggestion
My code compiled well in JDK1.4 but warning in JDK1.5.
hot spot optimization techniques?
Java 1.5 typed collections...