小编use*_*534的帖子

为什么我不能在java中像这样懒惰初始化静态长数组?

private static final long[] reservedFromIps;

static {
    reservedFromIps = {0l, 167772160l, 1681915904l, 
        2130706432l, 2851995648l, 2886729728l, 3221225984l, 3227017984l, 3232235520l, 
        3323068416l, 3325256704l, 3405803776l, 3758096384l, 4026531840l, 4294967295l}; 
}
Run Code Online (Sandbox Code Playgroud)

错误是"表达式的非法启动,而不是声明,;预期"

而以下工作正常:

private static final long[] reservedFromIps = {0l, 167772160l, 1681915904l, 
    2130706432l, 2851995648l, 2886729728l, 3221225984l, 3227017984l, 3232235520l, 
    3323068416l, 3325256704l, 3405803776l, 3758096384l, 4026531840l, 4294967295l}; 
Run Code Online (Sandbox Code Playgroud)

java static-members lazy-initialization

4
推荐指数
1
解决办法
1048
查看次数

这个字符串构造函数的实现如何工作(java)?

 public String(String original) {
     int size = original.count;
     char[] originalValue = original.value;
     char[] v;
     if (originalValue.length > size) {
         // The array representing the String is bigger than the new
         // String itself.  Perhaps this constructor is being called
         // in order to trim the baggage, so make a copy of the array.
         int off = original.offset;
         v = Arrays.copyOfRange(originalValue, off, off+size);
     } else {
         // The array representing the String is the same
         // size as the String, so …
Run Code Online (Sandbox Code Playgroud)

java string constructor field private

3
推荐指数
1
解决办法
105
查看次数