3 ms·
I really wish useful quality of life things like "?." would get added instead of this kind of stuff that really doesn't improve life all that much for most deve
by garblegarble 4y ago
I really wish useful quality of life things like "?." would get added instead of this kind of stuff that really doesn't improve life all that much for most development
- simplotek 4y ago> (...) instead of this kind of stuff that really doesn't improve life all that much for most development There are comments in this very discussion praising this change due to how this stuff really improves their life as a developer. Anyway, can you pass the link to your JEP with a proposal for "?." ?
- jeroenhd 4y agoThe Elvis operator was proposed for Java 7 and hasn't made it back in since. I'm sure you can put in the effort to write a proposal again but I doubt it'd stay up for long. I'm not going to put in the effort of fighting a committee that has probably already made up its mind when I can write Kotlin or C# instead. Maybe Manifold will add the operator somehow. That seems to be the place modern language features that the Java comities don't like end up.
- deleted 4y ago[deleted]
- jeroenhd 4y agoYou and me both. Java programmers don't seem to want it for some reason. However, Java has instead received `Optional` (in the shape of `Optional.ofNullable(variable).map(Clazz::getProperty).map(Clazz2::getProperty).orElseGet( () -> 42 );` rather than `variable?.getProperty()?.getProperty() ?: 42`). I don't know what the JCP EC was thinking going for this approach rather than the much more readable, modern approach, but I can't be too surprised about a language designed by committee refusing such improvements.
- vbezhenar 4y agoThis is useless operator. I can't imagine many places where it could be useful.
- MichaelNolan 4y agoI went from using Java to Kotlin at work, and I hate the “?.” notation. I’m sure it’s nice when used correctly, but it seems that people just use it everywhere and now the program went from “When I do x and it crashes” -> “When I do x nothing happens”. It hides errors and makes debugging more difficult. I love null being apart of the type system, but the safe call operator seems like a huge step backwards.
- grog454 4y ago?. Should generally be rare and can be combined with null coalescence to reduce occurrences: Void func doThing(state : State?) { var idx = state?.idx ?? -1 //No more ?. Needed }
- imtringued 4y agoWhy would people use it everywhere in Kotlin? I thought types weren't nullable by default. Also I don't see the difference between if(a != null) { a.b(); } and a?.b(). They won't result in NPEs either way and I see the former everywhere in Java as well.