Abhi
02/07/2018, 10:04 PMpublic static void showDialog(@NonNull FragmentActivity activity)
and I call it within a fragment using kotlin as Util.showDialog(fragment.activity)
. The compiler complains that Expected: FragmentActivity, Found: FragmentActivity?
Knowing that the activity will not be null when I call the method (i:e I call it right after onActivityCreated()
), which of the following would be a good way to handle the error:
- casting: fragment.activity as FragmentActivity
- non null assertion: fragment.activity!!
- let/if
blocks (but this will hide the exception and hurt me in the long run)Lucas Ribeiro
02/08/2018, 11:10 AMActivity!
), you can change the showDialog()
function to accept Activity?
and verify inside the function if it's notAbhi
02/08/2018, 6:12 PM!!
is the best way out