Random类的nextLong()方法的Javadoc表明了这一点
因为Random类使用只有48位的种子,所以此算法不会返回所有可能的长值.(随机javadoc)
实施是:
return ((long)next(32) << 32) + next(32);
Run Code Online (Sandbox Code Playgroud)
我看到它的方式如下:为了创建任何可能的长,我们应该生成具有相同似然性的64位的任何可能的位模式.假设调用next(int)给我们32个随机位,那么这些位的串联将是64个随机位的序列,因此我们生成具有相等似然性的每个64位模式.因此所有可能的长值.
我认为编写javadoc的人知道的更好,而且我的推理在某种程度上是有缺陷的.任何人都可以解释我的推理在哪里是不正确的,那么将返回什么样的多头?
我正在清理代码并更改对静态成员的所有访问权限,以便它们由定义它们的类限定.然而,这导致了以下困扰我的问题.
我有一个带有嵌套类的类.在这个嵌套类的注释中,我引用了周围类中的私有静态final字段.当这样做没有资格时(如下面D类的注释),这是有效的.但是,在添加类限定符时(如在类C上的注释中),编译器会告诉字段(下面的v)不可见.
public class VisibilityTest {
@interface A {
int f();
}
@A(f = VisibilityTest.v) //fails
private static class C {
int c = VisibilityTest.v; //works
}
@A(f = v) //works
private static class D {
int d = VisibilityTest.v; //works
}
private final static int v = 5;
}
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,变量都指向同一个字段,为什么会发生这种情况呢?
我正在尝试注释中的静态字段,并且遇到了我不了解的问题。
我使用以下代码:
@a
public class myAnnotMinimal {
public static void main(String[] args) {
System.out.println(myAnnotMinimal.class.getAnnotations().length);
}
}
@Retention(RetentionPolicy.RUNTIME)
@interface a {
Consumer<Integer> f1 = a -> {return;}; // -> 0
//Consumer<Integer> f2 = new B(); //-> 1
//Consumer<Integer> f3 = C::eat; //-> 1
//int f4 = 5; //->1
//Supplier<Integer> f5 = ()->5; //->1
}
class B implements Consumer<Integer> {
@Override
public void accept(Integer t) {
}
}
class C{
public static void eat(Integer t){
}
}
Run Code Online (Sandbox Code Playgroud)
现在,运行此命令时,我希望可以打印“ 1”,但是我得到的输出是“ 0”。当我删除f1字段并取消注释其他(f2-f5)字段时,输出为'1'。在我看来,这几乎像个虫子。我有什么想念的吗?我在Linux上使用jdk1.8.0_66。
由于这看起来像JDK中的错误,因此我提交了错误报告。到目前为止,错误报告已被接受。参见http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8147585 …