Skip to content

Instantly share code, notes, and snippets.

@amatkivskiy
Last active May 15, 2020 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amatkivskiy/b1222bcade61b9aed788d2bbcdde6a70 to your computer and use it in GitHub Desktop.
Save amatkivskiy/b1222bcade61b9aed788d2bbcdde6a70 to your computer and use it in GitHub Desktop.
// Arrange
data class Parent(val child: Nested?)
class Nested(val child: Nested?, val isValid : Boolean = false)
// Assume you got this object from the dark and deep internals of your app
val parentObj = getParentObjFromInternals()
// This is straightforward but it won't work
if (parentObj.child?.child?.child?.isValid) {
// Error.
// Type mismatch. Required: Boolean, Found: Boolean?
}
// So you need to workaround this
if (parentObj.child?.child?.child?.isValid == true) {
// Do something
}
fun getParentObjFromInternals() = Parent(Nested(Nested(Nested(null, true))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment