• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Byte Wrapper class

 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?/

Thanks.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12188
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not know literals are take int by default. Thanks for the reply Fred.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic