This question is more out of curiosity than is is out of a bug or something else.
When I generate a blank fragment from the Android Studio templates, the onCreateView method which returns a View, has the nullable question mark. The Android Studio highlights it in yellow and tips to remove the nullable sign since the onCreateView return a non nullable View.
Why doesn't Android Studio autogenerate it as non nullable from the start? Is it a bug or intentional? If intentional, why?
CodePudding user response:
I'm just guessing - returning null
from onCreateView
is perfectly fine in order to create a "headless fragment" but those are not really useful since viewmodels were introduced.
This might be a reason why onCreateView
return type is nullable but if you do override it then it's implied you want to return something from it so studio can only drop a hint.