java内部类 之private 属性对其他对象的访问限制

public class InnerClass1 {

    private class Content {
        private int i;





        public int value() {
            // TODO Auto-generated method stub
            return i;
        }

    }


    public Content getContent() {

        return new Content();
    }

    private class Description {

        private String lable;

        private Description(String lab) {
            this.lable = lab;

        }

        public String readLable() {
            return lable;
        }
    }
}
View Code

当客户端访问某外围类对象的private innterclass对象时  发现编译器会报错 提示可见性问题。这其实间接也表达了一种安全机制 如果你想完全隐藏内部类技术细节缺失可以这么做。

原文地址:https://www.cnblogs.com/zhangfengshi/p/9386399.html