Originally posted by Kasak Tahilramani:
Please correct me ,can I do something like this .
1: Byte b =new Byte((byte) 8);
Byte b1=new Byte(b);//2
2: Byte b =new Byte((byte) 8);
byte byteval=b;
3:
// this is the example from K&B book which says an error at line 1
but if I try to compile it executes fine .
a) int intval=Integer.valueOf("345");//line 1
System.out.println(intval);
b) Float f=new Float(12.3);
float f1=Float.valueOf(23.4f);
The valueOf methods of Integer return a reference to an Integer object. If you are using a JDK >= 1.5, then autoboxing will automatically convert the Integer to an int.
However, if you use a JDK < 1.5, then you will get a compile-time error on line 1.
The same thing is true for Byte. JDK >= 1.5 will automatically convert a Byte to a byte.
Also if JDK >= 1.5, then a Byte will automatically be converted to a byte so that you can call the constructor of Byte that accepts a byte.
[ December 31, 2006: Message edited by: Keith Lynn ]