Can someone explain to me why the first two exampl...
# android
m
Can someone explain to me why the first two examples of this lazy property don’t produce warnings, but the last does? The signature of
getParcelableExtra
is
Copy code
@Nullable
<T extends Parcelable> T getParcelableExtra(java.lang.String name)
Copy code
@Parcelize
data class ParceledData(val thing: String) : Parcelable

class MainActivity : AppCompatActivity {
    // Works as expected
    val data by lazy {
         intent.getParcelableExtra<ParceledData>("data") ?: throw Exception()
    }

   // Works as expected
   val data by lazy<ParceledData> {
         intent.getParcelableExtra("data") ?: throw Exception()
   }

    // Produces warning: Returning type parameter has been inferred to Nothing implicitly
    val data: ParceledData by lazy {
         intent.getParcelableExtra("data") ?: throw Exception()
    }
}
h
The problem is in the right side of the “elvis” operator
throw Exception()
. For the compiler it returns
Nothing
.