Comment on CSR 8251991: Hex formatting and parsing utility

Raffaello Giulietti raffaello.giulietti at gmail.com
Mon Mar 15 16:06:37 UTC 2021


Hi,

the javadoc of most of the methods listed in my previous post below reads:
     "The delimiter, prefix, suffix, and uppercase parameters are not used."

As these eventually constitute the whole state of an instance of this 
final class and as the state is not involved, it is possible to declare 
the methods as static.


If, for some reason, declaring the methods as static is not a choice, 
the next best thing is to clarify that
* HexFormat.of() always returns the same instance and thus
* absent any other instance, the recommended idiom for invoking any of 
the methods below is, for example,
     HexFormat.of().isHexDigit('F')
(because there are almost no additional costs wrt static methods.)

But I don't see a reason why they should be non-static. Just oversight?


Greetings
Raffaello


On 2021-03-08 11:52, Raffaello Giulietti wrote:
> Hello,
> 
> it appears that all of the following API methods in [1] can be declared 
> *static*, which makes them more useful in contexts where there's no 
> instance of HexFormat available or none is desired.
> 
> As 17 has not yet entered any formal phase, the change should be harmless.
> 
>    public boolean isHexDigit(int);
>    public int fromHexDigit(int);
>    public int fromHexDigits(java.lang.CharSequence);
>    public int fromHexDigits(java.lang.CharSequence, int, int);
>    public long fromHexDigitsToLong(java.lang.CharSequence);
>    public long fromHexDigitsToLong(java.lang.CharSequence, int, int);
> 
> Greetings
> Raffaello
> 
> ----
> 
> [1] https://bugs.openjdk.java.net/browse/JDK-8251991


More information about the core-libs-dev mailing list