![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2007
Posts: 3
Rep Power: 0
![]() |
Compiler error...why?
Byte b=new Byte(1); //<-here
|
|
|
|
|
|
#2 |
|
Sexy Programmer
|
The constructor for a Byte does not take an integer value but a String value instead. See below.
Byte b = new Byte("1");
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
Actually there are two constructors:
1. Byte(byte value) 2. Byte(String s) Example of each: public class ByteTest {
public static void main(String[] args) {
byte aByte = 1;
Byte byte1 = new Byte( aByte );
System.out.println( byte1 );
String strByte = "1";
Byte byte2 = new Byte( strByte);
System.out.println( byte2 );
}
}So to answer your question, you could create a Byte from an integer with a simple cast like so: Byte b = new Byte( (byte)1 ) ); |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do I take a square root? | Fall Back Son | C | 26 | Oct 23rd, 2006 12:24 PM |
| programming outside the compiler | TwilightProgrammers | C++ | 9 | Jun 4th, 2006 5:21 PM |
| [tutorial] Simple G++ compiler tutorial | coldDeath | C++ | 7 | Nov 27th, 2005 12:33 PM |
| DOS Compiler! | Starter | C++ | 11 | Apr 15th, 2005 10:14 PM |
| Newbie : need help with Dev-C++ compiler | gemini_shooter | C++ | 16 | Apr 12th, 2005 3:09 AM |