bringoff
11/28/2017, 6:51 AMgetActivity
in Fragment got @Nullable
annotation. But what should I do now in following situations? For example, I build DialogFragment. I need a context in onCreateDialog
method. To do something like this:
return MaterialDialog.Builder(context)
.title(R.string.invitation_to_team_dialog_title)
.content(buildDescriptionText())
.build()
onCreateDialog
method must return NonNull Dialog instance so I can’t use context?.let
call. And I really doubt context may be null on this stage (as well as activity in Fragment’s onCreateView
method, I suppose?). So I forced to use ugly !!
call. @jw as I know from your twitter these annotations were your endeavor. So, from your opinion, what should be an intended workaround in this situation? I don’t really like double exclamation point. It looks like very Java-ish way to care about nullability, sort of “I don’t care, whatever”gildor
11/28/2017, 7:40 AMval context = context ?: error("Context is null")
return MaterialDialog.Builder(context)
.title(R.string.invitation_to_team_dialog_title)
.content(buildDescriptionText())
.build()
Paul Woitaschek
11/28/2017, 8:43 AMgildor
11/28/2017, 8:46 AM!!
, but for cases when you can just return from function just easier to do that:
val context = context ?: return
Paul Woitaschek
11/28/2017, 9:30 AM