The moose likes Beginning Java and the fly likes CAST question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "CAST question" Watch "CAST question" New topic

CAST question

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

I am having a problem in my BOLDED code below whereby I am trying to convert a BIGINTEGER to an INT. Any direction or help would be appreciated. Here is my code:

// Check request version against response header version.
int responseVersion;
responseVersion = (int)responseheader.getVersion();
if (
) = 0

Transaction transaction = new Transaction();
return response;
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
responseVersion is not a BigInteger it is an int so it has no compareTo method.

What does the getVersion method return?
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387


Thanks for the reply. The getVersion method returns a BigInteger but I need to CAST that to an INT as well so I guess I should have put a (INT) in front of the second half of my assignment(?).

Sorry, still new to Java.

Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
You can't cast an Object to a primitive.
You can use the intValue() method in the BigInteger class to get the integer value.

Quaerendo Invenietis
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

Thanks, Mani.

Appreciate the help. That got it. Sorry, I should have looked at the API first.
[ July 06, 2005: Message edited by: Melinda Savoy ]
I agree. Here's the link:
subject: CAST question
It's not a secret anymore!