• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cast from an Object to a primitive long  RSS feed

 
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I posted a question before; but, that question was completely misleading. I feel sorry for that.

Let me try to do it better.
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
return (long[])theUserIDList.toArray(new long[theUserIDList.size()]);
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!