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

Make ThreadLocalRandom a final class

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 19
    • core-libs
    • None
    • minimal
    • The ThreadLocalRandom class has just one private constructor, so it's not expected that there will be any sub-classes of this class, either in the JDK or external applications.
    • Java API
    • SE

      Summary

      Update the java.util.concurrent.ThreadLocalRandom to be a final class.

      Problem

      The ThreadLocalRandom class has a sole private constructor:

      private ThreadLocalRandom() {
      ...

      So in essence, the ThreadLocalRandom class cannot have any sub class. Marking the ThreadLocalRandom as final would thus convey it more clearly that the class cannot be extended.

      Solution

      Update the class to final.

      Specification

      The proposed change looks as follows:

      --- a/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java
      +++ b/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java
      @@ -93,7 +93,7 @@ import jdk.internal.misc.VM;
      ...
      -public class ThreadLocalRandom extends Random {
      +public final class ThreadLocalRandom extends Random {

            jpai Jaikiran Pai
            jpai Jaikiran Pai
            Chris Hegarty, Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: