scala> Float.floatToI
On pressing tab here, it displays Float.floatToIntBits
. But,
scala> Float.floatToIntBits(2f)
<console>:6: error: value floatToIntBits is not a member of object Float
Float.floatToIntBits(2f)
^
scala> Float.floatToI
On pressing tab here, it displays Float.floatToIntBits
. But,
scala> Float.floatToIntBits(2f)
<console>:6: error: value floatToIntBits is not a member of object Float
Float.floatToIntBits(2f)
^
Float.floatToIntBits
tries to call method on the object scala.runtime.Float
(I think).
scala> Float
res2: Float.type = object scala.Float
You need java.lang.Float.floatToIntBits
:
scala> java.lang.Float.floatToIntBits(2f)
res1: Int = 1073741824
The REPL code-completion shows methods from all the Float
objects available on the path (i.e.scala.Float
scala.runtime.Float
and java.lang.Float
). However scala.Float
scala.runtime.Float
takes precedence over java.lang.Float
and hence the error.
The following works:
scala> import java.lang.{Float => JFloat}
import java.lang.{Float=>JFloat}
scala> JFloat.floatToIntBits(2f)
res5: Int = 1073741824