RFR 8164934: Optional.map() javadoc code example is incorrect
Paul Sandoz
paul.sandoz at oracle.com
Tue Nov 8 23:52:38 UTC 2016
Hi,
Please review an update to the api note of Optional.map() which embarrassingly contained erroneous code (labouring under the misapprehension that exception transparency is supported!).
I tweaked the example to refer to a Stream<URI> where a URI is transformed into a Path.
Paul.
diff -r df7e627c7224 src/java.base/share/classes/java/util/Optional.java
--- a/src/java.base/share/classes/java/util/Optional.java Tue Nov 08 15:28:44 2016 -0800
+++ b/src/java.base/share/classes/java/util/Optional.java Tue Nov 08 15:37:23 2016 -0800
@@ -214,20 +214,20 @@
* @apiNote
* This method supports post-processing on {@code Optional} values, without
* the need to explicitly check for a return status. For example, the
- * following code traverses a stream of file names, selects one that has not
- * yet been processed, and then opens that file, returning an
- * {@code Optional<FileInputStream>}:
+ * following code traverses a stream of URIs, selects one that has not
+ * yet been processed, and creates a path from that URI, returning
+ * an {@code Optional<Path>}:
*
* <pre>{@code
- * Optional<FileInputStream> fis =
- * names.stream().filter(name -> !isProcessedYet(name))
+ * Optional<Path> p =
+ * uris.stream().filter(uri -> !isProcessedYet(uri))
* .findFirst()
- * .map(name -> new FileInputStream(name));
+ * .map(Paths::get);
* }</pre>
*
- * Here, {@code findFirst} returns an {@code Optional<String>}, and then
- * {@code map} returns an {@code Optional<FileInputStream>} for the desired
- * file if one exists.
+ * Here, {@code findFirst} returns an {@code Optional<URI>}, and then
+ * {@code map} returns an {@code Optional<Path>} for the desired
+ * URI if one exists.
*
* @param mapper the mapping function to apply to a value, if present
* @param <U> The type of the value returned from the mapping function
More information about the core-libs-dev
mailing list