HUX布斯
如果您想隐藏内部类的私有成员,您可以与公共成员定义一个接口,并创建一个实现此接口的匿名内部类。下面的例子:class ABC{
private interface MyInterface{
void printInt();
}
private static MyInterface mMember = new MyInterface(){
private int x=10;
public void printInt(){
System.out.println(String.valueOf(x));
}
};
public static void main(String... args){
System.out.println("Hello :: "+mMember.x); ///not allowed
mMember.printInt(); // allowed
}}