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

Code example provided by RandomGeneratorFactory does not compile

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 17, 18
    • Fix Version/s: 19
    • Component/s: core-libs
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      JDK17 Windows 10 21H1 64bit

      A DESCRIPTION OF THE PROBLEM :
      In https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGeneratorFactory.html the code provided as:
      RandomGeneratorFactory<RandomGenerator> best = RandomGeneratorFactory.all()
               .sorted(Comparator.comparingInt(RandomGenerator::stateBits).reversed())
               .findFirst()
               .orElse(RandomGeneratorFactory.of("Random"));
      does not compile. The correct code appears to include:
          .sorted(Comparator.comparingInt(RandomGeneratorFactory<RandomGenerator>::stateBits).reversed())


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Attempt to compile the example code provided in the documentation using JDK17.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The example code should compile.
      ACTUAL -
      The example code does not compile.

      ---------- BEGIN SOURCE ----------
        public static void main(final String[] args)
        {
          RandomGeneratorFactory<RandomGenerator> best = RandomGeneratorFactory.all()
              .sorted(Comparator.comparingInt(RandomGenerator::stateBits).reversed())
              // .sorted(Comparator.comparingInt(RandomGeneratorFactory<RandomGenerator>::stateBits).reversed()) //<----- correct code
              .findFirst()
              .orElse(RandomGeneratorFactory.of("Random"));
          System.out.println(best.name() + " in " + best.group() + " was selected");

          RandomGenerator rng = best.create();
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Correct the example code.

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            jlaskey Jim Laskey
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: