In short my question is: Why should one choose for the first syntax instead of the second one? Are they completely the same?
Well, I would use neither of them, because both of them will generate intermediate Float
object, which is almost always not needed. And wherever it will be needed, we will get it to work with boxing.
For now, you should rather just use Float.parseFloat(String)
method, that generates a primitive float.
As far as similarity is concerned, no they are not completely the same. 2nd one involves auto-unboxing
from Float
to float
, while there is no unboxing
in first case. It does the conversion using the given method.