RFR: 8294693: Add Collections.shuffle overload that accepts RandomGenerator interface [v2]

Tagir F. Valeev tvaleev at openjdk.org
Wed Oct 12 13:26:30 UTC 2022


On Tue, 11 Oct 2022 02:00:40 GMT, Stuart Marks <smarks at openjdk.org> wrote:

>> Tagir F. Valeev has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Remove Random -> ThreadLocalRandom change
>
> src/java.base/share/classes/java/util/Collections.java line 485:
> 
>> 483:      *         list-iterator does not support the {@code set} operation.
>> 484:      * @since 20
>> 485:      */
> 
> It looks like this comment was copied from `shuffle(List, Random)` and `shuffle(List)` which is fine. But since this method is now preferred over the others, maybe we can reduce the duplication and have those other methods simply be defined in terms of this one. We'd have to come up with the right "weasel words" to describe the source of randomness used by `shuffle(List)`. In addition, if you don't want to deprecate the other methods, perhaps some wording can be found that clearly indicates this new method is now the preferred one.

I updated the documentation, please take a look. Deprecation sounds not a good idea, as if you want to use a randomness source that happens to extend Random class (e.g., ThreadLocalRandom.current()), compiler will link it to the old method. This is totally fine, and you should not get a deprecation warning.

-------------

PR: https://git.openjdk.org/jdk/pull/10520


More information about the core-libs-dev mailing list