Czar
05/02/2018, 9:04 AMrrader
05/02/2018, 9:05 AMkarelpeeters
05/02/2018, 9:05 AMkarelpeeters
05/02/2018, 9:05 AMtoString is defined on Any?.rrader
05/02/2018, 9:06 AMa?.b.toString().length ?: null.toString()karelpeeters
05/02/2018, 9:06 AMkarelpeeters
05/02/2018, 9:07 AMrrader
05/02/2018, 9:08 AMedwardwongtl
05/02/2018, 9:09 AMa?.b.c.d
a?.b can be non-null, but how can you be sure b.c is also non-null?
Think using a general case will make more sense.Czar
05/02/2018, 9:09 AMtoString() here's something from code I've seen in production (dumbed down for brevity)
fun prepareNextActionCommand(input: ParamsObject): Command {
fun null.toCommand() = DefaultActionCommand()
return input.action.toCommand().apply { /* stuff */ }
}rrader
05/02/2018, 9:10 AM?: null.toCommand()Czar
05/02/2018, 9:11 AMnull, so if your version is accepted, null.toCommand() will not execute toCommand() and will instead return nullrrader
05/02/2018, 9:13 AM?: doesn't mean if left is null execute right?edwardwongtl
05/02/2018, 9:14 AMrrader
05/02/2018, 9:15 AMnull.toCommand() will be executed, as neededCzar
05/02/2018, 9:15 AMnull.toString() won't be executed and null.toCommand() will 😄rrader
05/02/2018, 9:16 AM?:Czar
05/02/2018, 9:19 AM?:
Too much non-obvious behaviour in my opinion.rrader
05/02/2018, 9:23 AMa?.b.toString() will be reduced to null and we will have
null ?: null.toString()rrader
05/02/2018, 9:23 AMCzar
05/02/2018, 9:24 AM?: operator changing how method chaining works does not make sense to me personally