frank
07/18/2020, 6:39 PM!!
or ?.
in every call.
It's annoying, could be added a feature: Operator that spreads through the members.
Sample:
bob?.department?.head?.name
bob!!.department!!.head!!.name
Something like this: [Edit]
bob.department.head*?.name
bob.department.head*!!.name
@Alexey Belkov [JB] , You know if it is on the Road-MAP or if there is any request for this feature? Or would it not be viable?
Edit:
I'm new with Kotlin but I'm not understand Why this request is so unpopular. Someone to give Feedbackandylamax
07/18/2020, 9:34 PMfrank
07/18/2020, 9:52 PMfrank
07/18/2020, 10:01 PMif you see doing a bunch of double bangs, its not the language with problem, you need to recheck your code.
In cases that you use third-party libs of Java or Kotlin/JS (e.g. HTML Element) these usually happen and you can't control it. Sample with Kotlin/JS:
document.getElementById("lista")?.getElementsByTagName("li")?.get(2)
nschulzke
07/20/2020, 2:43 PMli
tags within that element, if it exists.
• There could be fewer than 3 of those li
tags.
Given how many assumptions you're making here, what those question marks tell you is that you really need to carefully think through what it would mean for any one of these expressions to be null, so that it falls back gracefully to some reasonable behavior. If you reduced them to a single operator, you wouldn't be forced to consider exactly what could go wrong.nschulzke
07/20/2020, 2:48 PMAlexey Belkov [JB]
07/20/2020, 6:25 PMfrank
07/22/2020, 4:58 PMI find that the frequent question marks serve as a guardrail for me.
If you reduced them to a single operator, you wouldn't be forced to consider exactly what could go wrongSingle operator can make a good combination with inlay hint of Intellij and show warnings in each null expression.