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对象时  发现编译器会报错 提示可见性问题。这其实间接也表达了一种安全机制 如果你想完全隐藏内部类技术细节缺失可以这么做。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM