guys, code style question about nullable context.....
# android
t
guys, code style question about nullable context.. (After api 27 android added
@Nullable
to
public Context getContext()
) I have method
getUserComponent(context: Context): UserComponent
, which is used inside
onCreate
across whole app. 1. First solution is to add
!!
everywhere
Copy code
App.getUserComponent(context!!)
But i can't look at all this
!!
without disgust feeling 2. Second is to make context param of getUserComponent nullable and fire exception in case of null
Copy code
fun getUserComponent(context: Context?) = context!!.getApp().legacyAppComponent
Is that ok to allow method to take nullable param, but throw exception in this case?