Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8263755

HexFormat 'fromHex' methods should be static

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 17
    • core-libs
    • None
    • source, binary
    • minimal
    • Hide
      The java.util.HexFormat was added in the current release (JDK 17) and it has not been released.
      Existing code that uses the instance methods will produce warnings about invoking static methods via a reference. Existing class files will need to be recompiled.
      Show
      The java.util.HexFormat was added in the current release (JDK 17) and it has not been released. Existing code that uses the instance methods will produce warnings about invoking static methods via a reference. Existing class files will need to be recompiled.
    • Java API
    • SE

      Summary

      HexFormat methods for converting from strings to numbers should be static methods instead of instance methods.

      Problem

      The isHexDigit and fromHex methods were specified as instance methods though their specification did not depend on any of the instance method parameters. The delimiter, prefix, suffix, and uppercase parameters are not used.

      As static methods they are more useful in contexts where no instance of java.util.HexFormat is available or none is desired.

      Solution

      Add the static modifier to the methods and remove references to instance parameters that are not relevant.

      Specification

      Add the static modifier to the following java.util.HexFormat methods.

      public static boolean isHexDigit(int);
      public static int fromHexDigit(int);
      public static int fromHexDigits(java.lang.CharSequence);
      public static int fromHexDigits(java.lang.CharSequence, int, int);
      public static long fromHexDigitsToLong(java.lang.CharSequence);
      public static long fromHexDigitsToLong(java.lang.CharSequence, int, int); 

      SpecDiff is attached.

            rriggs Roger Riggs
            rriggs Roger Riggs
            Naoto Sato
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: