RFR(m): 8140281 deprecate Optional.get()
Andrej Golovnin
andrej.golovnin at gmail.com
Fri Apr 29 15:30:06 UTC 2016
Hi Peter,
> ...even more Stream-y (with JDK 9 changes to Optional):
>
> otherMods
> .stream()
> .flatMap(mod -> finder.find(mod).stream())
> .forEach(mref -> ...);
>
>
> Yes, it takes some time for people to get used to new tools before they use them optimally. This is a normal learning process. So I wonder whether it is only the method name that is to blame for the observed percentage of wrong or sub-optimal usages of Optional or would it be more-or-less the same with a more descriptive name at this time.
>
> But the argument that getWhenPresent() is easier to spot than get() when reading code is on spot so at least some bugs would get spotted more quickly if the method stood out.
Even when you call this new method
Optional.dudeCallIsPresentBeforeCallingMe()
it won't help. Against the stupidity, the inability to read JavaDocs and
the laziness helps only a compiler error. Therefore when you really want
to help developers to avoid bugs due to wrong usage of Optional.get(),
then you must change the compiler to recognize the usage of Optional.get()
without the isPresent()-check and to raise an error in such cases.
I mean if IntelliJ is able to give you a hint that you use Optional.get()
without the isPresent()-check, then the Java compiler should be able
to do it too.
Just my two cents.
Best regards,
Andrej Golovnin
More information about the core-libs-dev
mailing list