RFR: JDK-8161230 ClassLoader: add resource methods returning java.util.stream.Stream

Andrej Golovnin andrej.golovnin at gmail.com
Thu Sep 8 18:41:34 UTC 2016


Hi Patrick,

>> 1362      * Returns a stream that loads the resources with the given name.
>> 1375      * <p> The loading of resources will occur when the returned stream is
>> 1376      * evaluated. If the loading of resources results in an
>> {@code IOException}
>> In reality however, no resources are loaded. Only URLs for all
>> resources that match the given name are created. To load the resources
>> you must open the connection on the returned URLs. Therefore I think
>> the JavaDocs do not reflect what the method does.
> 
> What do you suggest to write instead?

For the line 1362 maybe something like that:

Returns a stream whose elements are the URLs of all the resources with the given name.

And for the lines 1375 and 1376 you can use the wording suggested by Mandy.

> 
>> And one more thing. Because we have now only one method to get a
>> stream I think the constant RESOURCE_CHARACTERISTICS should be defined
>> inside the #resources()-method. It is not needed to define it as a
>> static final field.
> 
> The reason is to have the computation of the characteristics only at compile time not on each method call.

As explained by Paul, the bitwise OR-operator is evaluated by the Java compiler during the compilation time. Therefore there is no penalty at runtime if you define the constant inside the method.

Best regards,
Andrej Golovnin


More information about the core-libs-dev mailing list