Juanoterocas
09/09/2019, 10:14 PMif(x!=null && x.name.equals("name"))
{}
first evaluate if x is not null then second condition, second condition is not checked if x is null and then is false since && operator only true when all its true, must stop evaluating second condition, is this by desing? how could I do this in kotlin?Dominaezzz
09/09/2019, 10:16 PMShawn
09/09/2019, 10:19 PMif (x?.name == "name")
if (x != null && x.name == "name")
if you want the short-circuit semantics to be obviousJuanoterocas
09/09/2019, 10:27 PMMatt Thompson
09/09/2019, 11:40 PMtakeIf
- x?.takeIf { it.name == "name" }?.let { ... }
DALDEI
09/10/2019, 1:40 AMShawn
09/10/2019, 1:40 AMif
null-check every now and againDALDEI
09/10/2019, 1:44 AMval compilation: ScriptCompilationConfiguration.Builder.() -> Unit = {
jvm {
// limit or extend classpath
// "mylib.jar","another.jar", wholeClasspath = imTooLazy
dependenciesFromCurrentContext( wholeClasspath = true)
}
}
Matt Thompson
09/10/2019, 2:29 PMtakeIf
and let
in this case is not preferable to a simple if check... just sayin it's an option 🤷♂️