Created
September 2, 2016 16:57
-
-
Save LukaJCB/01861a044d2cd5dcbcd55804dc83d1a1 to your computer and use it in GitHub Desktop.
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
//So now after letting IntelliJ convert our file to Kotlin we get this: | |
//... but there's an error | |
class ExampleActivity : AppCompatActivity() { | |
private var foo: String? = "Bar" | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
foo = something | |
if (foo != null) { | |
doSomething(foo) | |
//Smart cast to 'String' is impossible, | |
// because 'foo' is a mutable property that could have been changed by this time | |
} | |
} | |
} | |
//In order for our call to 'doSomething' to actually be guaranteed to work we need foo to be Immutable AND Non-null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment