- 已关闭。**此问题需要debugging details。当前不接受答案。
编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
3天前关闭。
Improve this question
为什么这行代码有错误信息?
Random ran2 = new Random();
float distance = ran2.nextFloat(50f);
1条答案
按热度按时间j8yoct9x1#
方法
nextFloat(float)
在接口java.util.random.RandomGenerator
(docs.oracle.com
)中实现,该接口是在Java 17(en.wikipedia.org
)中引入的。使用JDK〈17编译此代码将导致编译错误:
有两种方法可以解决此问题:
RandomGenerator.nextFloat(float)
的功能(实际实现可以在jdk.internal.util.random.RandomSupport
(github.com
)中找到):