import java.util.*;
class Anonymous {
{
System.out.println("代码块:"+this.getClass().getName());
}
public Anonymous() {
System.out.println("无参构造函数:"+this.getClass().getName());
}
}
class aaa{
public aaa() {
Anonymous n = new Anonymous(){
{
System.out.println("Anonymous匿名类:"+this.getClass().getName());
}
};
System.out.println("n:"+n.getClass().getName());
List<String> list_1 = new ArrayList<String>(){
{
System.out.println("List匿名类:"+this.getClass().getName());
}
};
System.out.println("list_1:"+list_1.getClass().getName());
List<String> list_2 = new ArrayList<String>();
System.out.println("list_2:"+list_2.getClass().getName());
}
}
class bbb {
public bbb() {
Anonymous n = new Anonymous();
System.out.println("n:"+n.getClass().getName());
}
}
public class AnonymousDemo {
public void test1() {
Anonymous n = new Anonymous(){
{
System.out.println("Anonymous匿名类:"+this.getClass().getName());
}
};
System.out.println("n:"+n.getClass().getName());
List<String> list_1 = new ArrayList<String>(){
@Override
public int size() {
System.out.println("size");
return super.size();
}
{
System.out.println("List匿名类:"+this.getClass().getName());
}
};
System.out.println("list_1:"+list_1.getClass().getName());
System.out.println(list_1.size());
List<String> list_2 = new ArrayList<String>();
System.out.println("list_2:"+list_2.getClass().getName());
}
public void test2(){
System.out.println("--------------------");
aaa a = new aaa();
}
public static void test3(){
System.out.println("--------------------");
bbb b = new bbb();
}
public static void main(String[] args) {
test1();
test2();
test3();
}
}