Implicit Type Conversion In Java
In java any decimal literal is an Integer.Then why the byte b=4; does not generate a compilation error as we are trying to assign integer (larger data type) to an byte(smaller data type).If we try to do float f=4.5; then it gives the compliation error.Becasue any floating point literal is double.But why it does not hold good in case of the decimal litera?
i'm not sure but I think this has something to do with the loss of information and the precision of a floating point number. An integer of 4 can be converted to a byte of value 4 without any loss of information but with a floating point number you loose information by converting down from double to float. btw you cannot assign any integer, all ints lager than 127 will throw a compilation error