Java to Kotlin converter: more smartness about variables nullability

This commit is contained in:
Valentin Kipyatkov
2014-06-04 16:35:34 +04:00
parent f96721fa7e
commit 15ffb6768c
9 changed files with 104 additions and 12 deletions
@@ -0,0 +1,8 @@
//file
class C {
private String s = null;
void foo() {
s = "x"
}
}
@@ -0,0 +1,7 @@
class C() {
private var s: String? = null
fun foo() {
s = "x"
}
}
@@ -0,0 +1,8 @@
//method
// !specifyLocalVariableTypeByDefault: true
void foo(boolean b) {
String s = null;
if (b) {
s = "abc"
}
}
@@ -0,0 +1,7 @@
// !specifyLocalVariableTypeByDefault: true
fun foo(b: Boolean) {
val s: String? = null
if (b) {
s = "abc"
}
}
@@ -0,0 +1,5 @@
//method
// !specifyLocalVariableTypeByDefault: true
void foo(boolean b) {
String s = (b ? "abc" : null);
}
@@ -0,0 +1,7 @@
// !specifyLocalVariableTypeByDefault: true
fun foo(b: Boolean) {
val s: String? = ((if (b)
"abc"
else
null))
}