interface Destination{
String readLabel();
}public class TestParcel7{
public Destination dest(final String dest,final double price){
return new Destination(){
private long cost;
{
cost = Math.round(price);
if(cost > 100){
System.out.println("Over budget!");
}else{
System.out.println("lost");
}
}
private String label = dest;
public String readLabel(){return label;}
};
}
public static void main(String args[]){
    TestParcel7 p = new TestParcel7();
    Destination d = p.dest("Tanzania",101.35d);
    System.out.println(d.readLabel());
}
}方法中的匿名内部类在什么时候被创建?是调用方法的时候吗?

解决方案 »

  1.   

    哦,Sorry,看成是对象了,如果是内部类,确实是编译完毕后就存在了。
      

  2.   

    看下JVM的编译原理吧!无解。楼主给分!
      

  3.   

    编译后,看到 TestParcel7$1.class文件,证明它在编译时就产生了。
      

  4.   

    内部类的class文件在编译是创建,内部类的实例在new时创建。