943,679 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2524
  • Java RSS
Mar 26th, 2008
0

what is the wrong with Byte constructor which takes int value

Expand Post »
java Syntax (Toggle Plain Text)
  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

Java Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sasidharnet is offline Offline
8 posts
since Aug 2007
Mar 26th, 2008
0

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

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 );
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007
Mar 26th, 2008
0

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

Actually it works

if we do like this.

Byte b = 3;
Short s = 34;
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sasidharnet is offline Offline
8 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Plz gv me a example(sample code) how to connect the database into the JTable
Next Thread in Java Forum Timeline: Swing: default button problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC