日期:2014-05-20  浏览次数:20583 次

什么是匿名内部类
大家给我写个简单的例子,以及有什么注意事项

------解决方案--------------------
[code=Java][/code]public class Parcel6 {
public Contents cont() {
return new Contents() {
private int i = 11;
public int value() { return i; }
}; // Semicolon required in this case
}
public static void main(String[] args) {
Parcel6 p = new Parcel6();
Contents c = p.cont();
}
} ///:~
------解决方案--------------------
只会给一个例子,注意事项不是很懂~
Java code

public class Test {
    public static void main(String[] args) {
        Thread t = new Thread() {
            private int i = 0;
            public void run() {
                while(true) {
                    System.out.println("i = " + i++);
                }
            }
        };
        t.start();
    }
}