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