Why is it now preferred to do: ```var args = GameW...
# android
e
Why is it now preferred to do:
Copy code
var args = GameWonFragmentArgs.fromBundle(requireArguments())
instead of:
Copy code
var args = GameWonFragmentArgs.fromBundle(arguments!!)
I understand it eliminates the ugly
!!
, but it still will likely lead to an error (
IllegalStateException
rather than
NullPointerException
). This was asked on Stack Overflow but not really answered. ScoreFragmentArgs.fromBundle(requireArguments())
l
I think it's mostly so that the error speaks a little more than a generic NPE
✔️ 1
☝️ 1
i
The error message also gives you the specific Fragment instance (class name, unique ID, etc.) that lets you correlate that with a specific Fragment with other operations i.e., if you enabled FragmentManager debug logging: https://developer.android.com/reference/androidx/fragment/app/FragmentManager#enableDebugLogging(boolean)
🙏 1
e
i
Seems like you have a pretty good answer there already
e
@Ian Lake The existing answer doesn't explain why IllegalStateException is better, which your answer here did.
I summarized you reply to Stack Overflow. Please let me know, or change, if you don't like how I referenced you. https://stackoverflow.com/a/66361013/631051
i
I guess you didn't see my answer? https://stackoverflow.com/a/66357610/1676363
e
Thanks, @Ian Lake. I deleted my answer once I saw yours. Maybe we had a race condition. 😉