Operator '==' cannot be applied to Float and Int in Kotlin

Warning:
Operator '==' cannot be applied to Float and Int in Kotlin

I come accross this warning/error inside RatingBar.setOnRatingBarChangeListener() method:

ratingbar_rateusfive_screen1.setOnRatingBarChangeListener { ratingBar, rating, fromUser ->
           
            if (rating == 5) {  // Warning in this line
            }
            }

Reason is that he rating variable is of Float type and comparing it with integer 5.
So after converting 5 to 5f it worked fine>

ratingbar_rateusfive_screen1.setOnRatingBarChangeListener { ratingBar, rating, fromUser ->
           
            if (rating == 5f) {
            }
            }

No comments:

Post a Comment

Popular Posts