-
forced casting
Hi I wnat to know the diffrent between the 2 code:
why a' doesnt work and b' does?
a.
{ public class PlusExample
{ public static void main(String[] args)
{
int i = 0;
double d = 1.0;
i = i + d;
System.out.println(i);
}
b.
{
public class PlusExample
{
public static void main(String[] args)
{
int i = 0;
double d = 1.0;
i += d;
System.out.println(i);
}
Thanks
}
-
(double posted in advance section as well)
b: i assume the compiler is smart enough to autocast d to int then add to i. but in a: it adds i and d first so you get a double value. then trying to assing an int to a double is an error.