Provide ThreadLocalRandom wrapper only on JDK8 as it is buggy in JDK7
This commit is contained in:
@@ -21,6 +21,8 @@ import java.util.regex.MatchResult
|
||||
import java.util.regex.Matcher
|
||||
import kotlin.internal.PlatformImplementations
|
||||
import kotlin.internal.jdk7.JDK7PlatformImplementations
|
||||
import kotlin.random.Random
|
||||
import kotlin.random.jdk8.PlatformThreadLocalRandom
|
||||
|
||||
internal open class JDK8PlatformImplementations : JDK7PlatformImplementations() {
|
||||
|
||||
@@ -34,4 +36,6 @@ internal open class JDK8PlatformImplementations : JDK7PlatformImplementations()
|
||||
null
|
||||
}
|
||||
|
||||
override fun defaultPlatformRandom(): Random = PlatformThreadLocalRandom()
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlin.random.jdk8
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "CANNOT_OVERRIDE_INVISIBLE_MEMBER")
|
||||
internal class PlatformThreadLocalRandom : kotlin.random.AbstractPlatformRandom() {
|
||||
// TODO no bridge generated for covariant override
|
||||
override val impl: java.util.Random get() = ThreadLocalRandom.current()
|
||||
|
||||
override fun nextInt(origin: Int, bound: Int): Int = ThreadLocalRandom.current().nextInt(origin, bound)
|
||||
override fun nextLong(bound: Long): Long = ThreadLocalRandom.current().nextLong(bound)
|
||||
override fun nextLong(origin: Long, bound: Long): Long = ThreadLocalRandom.current().nextLong(origin, bound)
|
||||
override fun nextDouble(bound: Double): Double = ThreadLocalRandom.current().nextDouble(bound)
|
||||
override fun nextDouble(origin: Double, bound: Double): Double = ThreadLocalRandom.current().nextDouble(origin, bound)
|
||||
}
|
||||
Reference in New Issue
Block a user