Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CAST question

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 (
//responseheader.getVersion().compareTo(
responseVersion.compareTo(
beginTransactionRequest.getHeader().getVersion()
) = 0
)

{
Transaction transaction = new Transaction();
response.setTransactionID(BigInteger.valueOf(transaction.GetId()));
}else{
responseheader.setStatus(Status.fromString("VersionNotSupported"));
}
return response;
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven,

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.

Regards.
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't cast an Object to a primitive.
You can use the intValue() method in the BigInteger class to get the integer value.

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic