RFR - JDK-8203442 String::transform (Code Review)

Peter Levart peter.levart at gmail.com
Tue Nov 13 10:59:17 UTC 2018



On 9/21/18 12:22 PM, Alan Bateman wrote:
> On 18/09/2018 18:52, Jim Laskey wrote:
>> Please review the code for String::transform. The goal is to provide 
>> a String instance method to allow function application of custom 
>> transformations applied to an instance of String.
>>
>> webrev: http://cr.openjdk.java.net/~jlaskey/8203442/webrev/index.html
>> jbs: https://bugs.openjdk.java.net/browse/JDK-8203442
>> csr: https://bugs.openjdk.java.net/browse/JDK-8203703
> I hate to bring up naming but if I have a Stream<String> or 
> Optional<String> then I'll use the "map" method to apply the mapping 
> function.

An argument against re-using the name map() for this String method is 
that Stream.map() and Optional.map() act on the element(s) of the 
"container" the method is invoked upon, and return the same raw part of 
type with type parameter adjusted, while String.map() would be passing 
the target object itself to the function and returning an arbitrary 
type. So in this regard, it is a different operation. The same method as 
suggested for String would be usable on Stream too, but it would have to 
be called differently on Stream. Imagine defining this method on Object. 
It would clash with Stream.map() and Optional.map() if it was called 
map(). So I don't think .map() is the best name for this method.

Regards, Peter



More information about the core-libs-dev mailing list