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());
}
}方法中的匿名内部类在什么时候被创建?是调用方法的时候吗?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货