An Integer not a Float . Casting will work with objects if Integer subclass of Float , but it is not.
Java will not automatically decompress Integer into int , drop it to Float , and then automatically to Float when the only code to run this desired behavior is a cast.
Interestingly, this works:
Float b = (float)i;
Java will be automatically-unbox i to int , then there will be an explicit cast to Float (a extension of the primitive conversion, JLS 5.1.2 ), then the assignment conversion automatically translates it to Float .
rgettman
source share