Java to Kotlin converter: more smartness about variables nullability
This commit is contained in:
@@ -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))
|
||||
}
|
||||
Reference in New Issue
Block a user