小编use*_*771的帖子

为什么内部类可以访问另一个内部类的私有成员?

我刚刚发现内部类可以像这样访问另一个内部类的私有成员:

public class TestOutter {
    class TestInner1 {
        private int mInt = 1;
    }
    class TestInner2 {
        public int foo(TestInner1 value) {
            return value.mInt;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

TestInner2的方法foo可以访问TestInner1的私有成员mInt.

但我以前从未见过这种情况.我不知道让代码进入TestInner2可以访问TestInner1的私有成员的含义.

我在谷歌搜索了内部类,没有一个搜索结果显示内部类有这个功能.我也查阅了Java语言规范,但它仍未提及.

java

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

Go中的func实现在哪里附加?

我非常感兴趣,并尝试阅读go函数的实现.我发现其中一些功能没有实现.

如追加或致电:

// The append built-in function appends elements to the end of a slice. If
// it has sufficient capacity, the destination is resliced to accommodate the
// new elements. If it does not, a new underlying array will be allocated.
// Append returns the updated slice. It is therefore necessary to store the
// result of append, often in the variable holding the slice itself:
//  slice = append(slice, elem1, elem2)
//  slice = append(slice, anotherSlice...)
// As …
Run Code Online (Sandbox Code Playgroud)

go

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

标签 统计

go ×1

java ×1