JDK 13 RFR of JDK-8217000: Refactor Class::methodToString
joe.darcy at oracle.com
Tue Jan 22 21:10:56 UTC 2019
Catching up on email, at least to my eye, the current version is easier
to read than the proposed refactoring in both cases.
I wouldn't expect this code to be performance critical so I'm inclined
to leave the code as-is unless a performance motivation is found.
Thanks for the comments,
On 1/16/2019 1:21 AM, Remi Forax wrote:
> Hi Joe,
> in j.l.Class, in methodToString, can you change
> sb.append(getName() + "." + name + "(");
> because using the concatenation inside a StringBuilder creates another StringBuilder (java.lang doesn't use the StringConcatFactory).
> return typeVar.getName() + " extends " +
> .collect(Collectors.joining(" & "));
> can be written
> return Arrays.stream(bounds)
> .collect(Collectors.joining(" & ", typeVar.getName().concat(" extends "), ""));
> which also avoid the creation of an intermediary StringBuilder (at the cost of the code being less readable).
> (in that case, you have also to change the same code in Executable).
> ----- Mail original -----
>> De: "joe darcy" <joe.darcy at oracle.com>
>> À: "Stuart Marks" <stuart.marks at oracle.com>
>> Cc: "core-libs-dev" <core-libs-dev at openjdk.java.net>
>> Envoyé: Mercredi 16 Janvier 2019 04:05:05
>> Objet: Re: JDK 13 RFR of JDK-8217000: Refactor Class::methodToString
>> Good catch on the 3-argument joining in this case; I'll push with that
>> Thanks for the review,
>> On 1/15/2019 3:19 PM, Stuart Marks wrote:
>>> On 1/14/19 7:41 PM, Joe Darcy wrote:
>>>> PS And for good measure, made analogous changes in Executable.java:
>>> Thanks for following up on this. Overall, looks good. One point:
>>> 114 sb.append('(');
>>> 116 sb.append(Arrays.stream(parameterTypes)
>>> 117 .map(Type::getTypeName)
>>> 118 .collect(Collectors.joining(",")));
>>> 120 sb.append(')');
>>> I think you can use the 3-arg form of joining() here, since the prefix
>>> and suffix are included even if the stream is empty.
More information about the core-libs-dev