[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ok..one of those..I RTFM...but..I'm dumb...what can I say..



ooops..I meant... 6 < 128...see it's that complex math getting the best 
of me....
still..pulease...hellwwp..

Fido wrote:

>     I'm trying to understand a key concept of implicit conversion in 
> Java.  Explain to me if you have the following code:
> 
> //  file Wannaknow.java =)
> 
> class Wannaknow
> {
>   public static void main(String[] args)
>   {
>       byte b = 2;
>       byte b1 = 3;
>       b = b * b1;
>       System.out.println(b);
>   }
> }
> 
> 
> ----
> 
> ....how in the world you get a compile error that says this:
> 
> Wannaknow.java:7: possible loss of precision
> found   : int
> required: byte
>               b = b * b1;
>                     ^
> 1 error
> 
> ----
> 
>   Apparently, I'm not understanding something...yet...can't a byte 
> hold a value from -2^7 through 2^7-1?  Which would equals -128 through 
> 127 right? Why is this requiring an int, a value of -2^31 to 2^31-1?
> 
>   From my math experience (be it I only passed 5th grade math - 
> addition, subtraction, multiplication, and division of 2-digit 
> numbers), 2*3 is 6 and 6 > 127.  So, where's my reasoning wrong?  I 
> know my infinite stupidity is greater than someone's infinite 
> knowledge of Java, who could be classified as a 'god of Java,' but, I 
> do think one of you Herculean characters can help this meager Sysiphus.
> 
> Thanks.
> Fido - a wannabe man from a distant place...far far away...
>