When I change the container
type in my onCreateView()
from Viewgroup?
to Viewgroup
I get this error:
Why is this?
You are getting an error because ViewGroup is marked as nullable in the fragment parent class. In Kotlin '?' indicates that this value can be null in Kotlin. In Kotlin any variable can be either nullable or non-nullable. Kotlin provides compile-time error for nullability. You get compile time error if you try to assign null values to a non-nullable variable. You cannot make nullable parameter in parent class non-nullable in child class function intended as overridden function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With