在一些多线程程序中比较常见,有点变态,呵呵。
/**
* 匿名类.
*
* @author leizhimin 2009-7-17 15:56:17
*/
public class Test3 {
public Foo f = new Foo() {
public void say() {
System.out.println( "O(∩_∩)O哈哈~!");
}
};
public Foo test() {
return new Foo() {
public void say() {
System.out.println( "say foo!");
}
};
}
public static void main(String[] args) {
Test3 t = new Test3();
t.f.say();
t.test().say();
}
}
interface Foo {
void say();
}
* 匿名类.
*
* @author leizhimin 2009-7-17 15:56:17
*/
public class Test3 {
public Foo f = new Foo() {
public void say() {
System.out.println( "O(∩_∩)O哈哈~!");
}
};
public Foo test() {
return new Foo() {
public void say() {
System.out.println( "say foo!");
}
};
}
public static void main(String[] args) {
Test3 t = new Test3();
t.f.say();
t.test().say();
}
}
interface Foo {
void say();
}
运行结果:
O(∩_∩)O哈哈~!
say foo!