RFR 8164934: Optional.map() javadoc code example is incorrect (original) (raw)
Chris Hegarty chris.hegarty at oracle.com
Wed Nov 9 09:19:43 UTC 2016
- Previous message: RFR 8164934: Optional.map() javadoc code example is incorrect
- Next message: RFR 8132097: Stream.generate should use a covariant Supplier as parameter
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 8 Nov 2016, at 23:52, Paul Sandoz <paul.sandoz at oracle.com> wrote:
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 where a URI is transformed into a Path.
This looks fine Paul.
-Chris.
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}: + * 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
}: * *{@code- * Optional fis = - * names.stream().filter(name -> !isProcessedYet(name)) + * Optionalp = + * uris.stream().filter(uri -> !isProcessedYet(uri)) * .findFirst() - * .map(name -> new FileInputStream(name)); + * .map(Paths::get); * } * - * Here, {@code findFirst} returns an {@code Optional}, and then - * {@code map} returns an {@code Optional} for the desired - * file if one exists. + * Here, {@code findFirst} returns an {@code Optional}, and then + * {@code map} returns an {@code Optional} for the desired + * URI if one exists. * * @param mapper the mapping function to apply to a value, if present * @param The type of the value returned from the mapping function
- Previous message: RFR 8164934: Optional.map() javadoc code example is incorrect
- Next message: RFR 8132097: Stream.generate should use a covariant Supplier as parameter
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]