This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Byte Wrapper class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Byte Wrapper class" Watch "Byte Wrapper class" New topic

Byte Wrapper class

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 629
Hi all,

I am trying to do this,

but it's giving me a compilation error as constructor Byte(int) is not defined. Why is it taking 10 as an int? But when I do this, it's working!!

Can someone tell me why?/


Be Humble... Be Nice.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11688

because literals are taken as ints by default. The compiler is smart enough to figure out that

byte b=10;

is ok. However, there is no constructor for a Byte that takes an int, so it fails.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 629
I did not know literals are take int by default. Thanks for the reply Fred.
I agree. Here's the link:
subject: Byte Wrapper class