小编sar*_*off的帖子

为什么Java不允许我通过同一个类的方法访问私有方法?

我的代码看起来像这样:

public class A<T extends A> {
    private T one() { return (T) this;}

    protected T two() { return (T) this;}

    protected void three() { two().one(); }
}
Run Code Online (Sandbox Code Playgroud)

IntelliJ告诉我"one()在A中有私人访问权限",但是,嘿,为什么我不能调用同一个类的私有成员?

java generics inheritance casting

22
推荐指数
3
解决办法
2427
查看次数

为什么javac有时会创建不必要的变量副本?

我的代码看起来像这样:

boolean[] array = new boolean[200];
int[] indexes = {10, 42, 62, 74};
while(true) {
    //some code here
    StringBuilder sb = new StringBuilder();
    for (int j : indexes) {
        sb.append(array[j] ? '1' : '0');
    }
}
Run Code Online (Sandbox Code Playgroud)

字典代码:

ASTORE 3 //"indexes" array
...
ALOAD 3
ASTORE 8
ALOAD 8
ARRAYLENGTH
...
Run Code Online (Sandbox Code Playgroud)

我不确定为什么javac复制引用数组到另一个本地var.

java bytecode javac

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

标签 统计

java ×2

bytecode ×1

casting ×1

generics ×1

inheritance ×1

javac ×1