what is the wrong with Byte constructor which takes int value

Reply

Join Date: Aug 2007
Posts: 8
Reputation: sasidharnet is an unknown quantity at this point 
Solved Threads: 0
sasidharnet sasidharnet is offline Offline
Newbie Poster

what is the wrong with Byte constructor which takes int value

 
0
  #1
Mar 26th, 2008
  1. class WrapperTest
  2. {
  3. public static void main(String[] args){
  4. Byte b = new Byte(3);
  5. Short s = new Short(34);
  6. }
  7. }

when I try to compile this is the problem I got

  1. G:\WORK PLACE\work>javac WrapperTest.java
  2. WrapperTest.java:4: cannot find symbol
  3. symbol : constructor Byte(int)
  4. location: class java.lang.Byte
  5. Byte b = new Byte(4);
  6. ^
  7. WrapperTest.java:5: cannot find symbol
  8. symbol : constructor Short(int)
  9. location: class java.lang.Short
  10. Short s = new Short(34);
  11. ^
  12. 2 errors


Please tell me What is the problem of that constructor.
Last edited by WolfPack; Mar 26th, 2008 at 9:32 am. Reason: Added code tags. USe them when you post code.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,625
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 221
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: what is the wrong with Byte constructor which takes int value

 
0
  #2
Mar 26th, 2008
Probably because there isn't such constructor.
API for Byte object
API for Short object
The values in the parenthesis are not treated as byte and short but as int. I haven't try this and I don't know if it will work so don't blame me, but try:
Byte b = new Byte( (byte)3 );
Short s = new Short( (short)34 );
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 8
Reputation: sasidharnet is an unknown quantity at this point 
Solved Threads: 0
sasidharnet sasidharnet is offline Offline
Newbie Poster

Re: what is the wrong with Byte constructor which takes int value

 
0
  #3
Mar 26th, 2008
Actually it works

if we do like this.

Byte b = 3;
Short s = 34;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC