This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing a byte as a parameter
 
Similar Threads
Self Test Question on Arrays by Kathy's Book
Declaring and initializing instance variables
for loop and byte to int coversion.
reading a file by bits
public static int binarySearch(byte[] a,