Created
February 20, 2020 13:35
-
-
Save gelin/2aa987b96cfd888e5308c3453496ac85 to your computer and use it in GitHub Desktop.
Type inference in Kotlin for Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Java | |
newIntent.setData(intent.getParcelableExtra(Intent.EXTRA_STREAM)); //compilation error | |
newIntent.setData(intent.<Uri>getParcelableExtra(Intent.EXTRA_STREAM)); //explicit type declaration | |
newIntent.setData((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM)); //explicit type cast | |
//Kotlin | |
newIntent.setData(intent.getParcelableExtra(Intent.EXTRA_STREAM)) //implicit type inference! | |
val stream = intent.getParcelableExtra(Intent.EXTRA_STREAM) //compilation error | |
val stream : Uri = intent.getParcelableExtra(Intent.EXTRA_STREAM) //explicit type inference | |
newIntent.setData(stream) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment