I am trying to convert primitive float
from java to Float
in kotlin like this:
kotlinFloat = myJavaObject.floatProperty()
But I am getting error that the types are not compatible etc.
I was looking like everywhere to find the answer but I was not able to. I was trying to create Float object -> Float(myJavaObject.floatProperty())
but it is failling since Float constructor is private.
I am very new to kotlin and I know this sounds stupid but I was trying to find the answer for like 20 minutes and could not find any.
Kotlin has to___
extension methods for things like this. What you need is toFloat()
kotlinFloat = myJavaObject.floatProperty().toFloat()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.