import java.util.Random;
public class TypeDemo1 {
public static void main(String[] args) {
Random r = new Random();
int d = r.nextInt(100,300);
System.out.println(d);
}
}
实际使用时会提示构建错误,提示内容为
java: 对于nextInt(int,int), 找不到合适的方法
方法 java.util.Random.nextInt()不适用
(实际参数列表和形式参数列表长度不同)
方法 java.util.Random.nextInt(int)不适用
(实际参数列表和形式参数列表长度不同)
但是官方文档里面关于nextInt(origin,bound)是有定义的:
default int nextInt(int origin, int bound) {
RandomSupport.checkRange(origin, bound);
return RandomSupport.boundedNextInt(this, origin, bound);
}