Home Tutorialhelp Comment A Byte object *can* be cast to a double

 
 

Comment

JC
A Byte object *can* be cast to a double,
July 22, 2010 at 5:11 PM

"Can a Byte object be cast to a double value?"

The author says no, but either his post is old or he forgot about auto-boxing.

In Java 6 it is possible to do this:


Byte b = new Byte("1");
System.out.println(b);
double a = (double)b; //Boxing turns the Byte in a byte automagically. You can then cast the byte as a double
System.out.println(a);

The output is:

1
1.0

View All Comments
Related Tutorial and Articles

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.