这串代码是引自一个学习博客:http://blog.csdn.net/chenssy/article/details/13170015
package testNote1;
public class OutClass {
public InnerClass getInnerClass(final int age,final String name){
return new InnerClass() {
int age_ ;
String name_;
//构造代码块完成初始化工作
{
if(0 < age && age < 200){
age_ = age;
name_ = name;
}
}
public String getName() {
return name_;
}
public int getAge() {
return age_;
}
};
}
public static void main(String[] args) {
OutClass out = new OutClass();
InnerClass inner_1 = out.getInnerClass(201, "chenssy");
System.out.println(inner_1.getName());
InnerClass inner_2 = out.getInnerClass(23, "chenssy");
System.out.println(inner_2.getName());
}
}
我在想上面的代码是不是少了定义类,如:
package testNote1;
public class InnerClass {
public String name_;
public int age_;
public String getName() {
return name_;
}
public int getAge() {
return age_;
}
}
如果是这样的话,代码中的内部类中下图的部分是否定义多余了: