aspose file tools
The moose likes Beginning Java and the fly likes Passing a byte as a parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Passing a byte as a parameter" Watch "Passing a byte as a parameter" New topic
Author

Passing a byte as a parameter

Dave Merrill
Greenhorn

Joined: Apr 16, 2005
Posts: 25
Say I've got a method that takes a byte value as a parameter:How can I call that in such a way that the incoming parameter is seen as type of byte?

You can do this:but that seems clunky, so j-newb me is wondering if there's a better way. Just using hex notation by itself doesn't seem to do it; you have to explicitly cast the value to a byte.

Is that how you have to do it?

Thanks
Stuart Gray
Ranch Hand

Joined: Apr 21, 2005
Posts: 410
Yep, if you are hardcoding constants like that they are assumed to be ints so you must downcast them.
Dave Merrill
Greenhorn

Joined: Apr 16, 2005
Posts: 25
OK, thanks. Downcast I shall
Edwin Keeton
Ranch Hand

Joined: Jul 10, 2002
Posts: 214

Or even better, don't pass literal values as parameters.


SCJP, SCWCD
Dave Merrill
Greenhorn

Joined: Apr 16, 2005
Posts: 25
Originally posted by Edwin Keeton:
Or even better, don't pass literal values as parameters.

Understood; this came up in a text fixture context, where more setup seemed bulky and unneccesary.

The other option is to use an int, so this whole question goes away.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Passing a byte as a parameter