File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion 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: 11957

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
It's not a secret anymore!