I think you’ve said why in your question, but just for clarity:
Double(double)
works just fine if you pass it a float
, so there’s no need for Double(float)
. This is because in a constructor invocation (JLS§5.3), a widening primitive conversion (JLS§5.1.2) is allowed. float
to double
is a widening primitive conversion.
But Float(float)
would not be just fine if you passed it a double
; you’d get a warning of a loss of precision because that’s a narrowing primitive conversion (JLS§5.1.3). So by providing a Float(double)
constructor which explicitly states it will lose precision, the API makes it possible to write code calling Float
‘s constructor with a double
without the warning. (You could argue whether that’s a good thing vs. having callers do the explicit (float)
cast when making the call, but…)
3
solved Why does Float has a constructor that allows double as an argument while Double doesn’t have a constructor with float as an argument in JAVA?