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
static class Person { | |
String name; | |
} | |
public void printName(Person person) { | |
if (person.name != null) { | |
foo(person.name.length()); | |
} | |
} |
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
data class Car(val make: String, val model: String, val registration: String) |
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
//* let | |
fun <T, R> T.let(f: (T) -> R): R = f(this) | |
//Scoping | |
Person.getName().let { name -> | |
print(name) | |
} | |
// name is no longer visible here | |
//To check for null values |
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
//**Attempting to assign null to a regular variable** | |
var hello: String = "hello" | |
hello = null // compilation error | |
//**Null safety** | |
//By checking for Null | |
val b = "kotlin" |
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
public class Car { | |
private String make; | |
private String model; | |
private String registration; | |
public String getmake() { | |
return make; | |
} |
NewerOlder