Home:ALL Converter>Java-Optional versus C++-optional

Java-Optional versus C++-optional

Ask Time:2019-11-04T01:45:59         Author:towi

Json Formatter

Am I right in assuming that the Java-Optional does not have much todo with the C++17-optional?

I know Javas Optional mostly from use in the Stream-API, e.g.:

Optional<Integer> op  = Optional.empty(); 
op.stream().forEach(System.out::println); 

I know it has its uses as a return value as well (not so much as parameter). But concerning this kind of use this is not applicaple to the C++-optional, right?

Or is it "Monads" again, the thing no-one can explain after understanding it? Does the C++-optional have in fact everything to do with Monads, and so have Java-Streams, and thus C++--optional is comparable to Java-Optional? What would be an comparable example, then?

Author:towi,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58682923/java-optional-versus-c-optional
yy