RFR: 8341566: Adding factory for non-synchronized CharSequence Reader [v3]

Alan Bateman alanb at openjdk.org
Mon Oct 7 07:41:36 UTC 2024


On Sun, 6 Oct 2024 14:50:48 GMT, Markus KARG <duke at openjdk.org> wrote:

>> src/java.base/share/classes/java/io/Reader.java line 174:
>> 
>>> 172:      * @since 24
>>> 173:      */
>>> 174:     public static Reader of(CharSequence c) {
>> 
>> Should we give this factory a more specific name so we don't clash in the future? For example, if we add another factory `of(A a)` for interface `A`, then it would be confusing to have an instance of `interface C extends CharSequence, A` to be passed to `of`.
>
> I do not see what is "confusing" in that case, as the caller still gets what he intends: a reader for the passed source. I also wonder how likely that case actually is. Anyways, I may be biased as I proposed `of`.
> 
> @AlanBateman WDYT?

You'll get different opinions on naming, personally I think Reader.of(cs) is very readable at use-sites. There are several other static methods named "of" added in other areas in recent years.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21371#discussion_r1789694010


More information about the core-libs-dev mailing list