Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Object to int?  RSS feed

 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to change an object to an int. I have tried to change it to Integer then to int I keep geting a ClassCastException
I am going from a vector and want an int.

Integer b = (Integer)POI[0].elementAt(0);
int n = b.intValue();
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are the objects stored in the Vector actually Integers? If so I see no reason you should get a ClassCastException here.
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just for debugging purposes, I would try:

 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it working REALLY working. Thanks everyone I figured out what I was doing wrong.
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to JDK 1.5 generics feature. You will not have these kinds of runtime issues. You will know it at compile time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!