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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles