Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing a byte as a parameter

 
Dave Merrill
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, if you are hardcoding constants like that they are assumed to be ints so you must downcast them.
 
Dave Merrill
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thanks. Downcast I shall
 
Edwin Keeton
Ranch Hand
Posts: 214
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or even better, don't pass literal values as parameters.
 
Dave Merrill
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic