Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

doubles cannot be converted to java.lang.Float  RSS feed

 
Lalit Sahu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
     
It showing error at 37 lines,Incompatible types:doubles cannot be converted to java.lang.Float
 
  
    
       
 
Campbell Ritchie
Marshal
Posts: 55745
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nam Lalli wrote: . . . doubles cannot be converted to java.lang.Float . . .
No, of course they can't. Don't use float or Float, unless some API forces you to.
You can cast a double to a float, which is a narrowing primitive conversion, but why would you want to?
If you try to convert a double to a Float, however, that is a narrowing primitive conversion followed by a boxing conversion, and the compiler cannot make both conversions together. You cannot cast a Double to a Float or vice versa. I shall let you work out why for yourself
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!