定义一个测试接口:
public interface IContent {
int getValue();
void f();
}
然后可以在方法体里面直接返回return new IContent()
public class InternalClass {
public IContent getContent(){
return new IContent(){
private int value ;
private int v2;
{
value = 12;
v2 = 10;
}
public int getValue(){return value + v2;}
public void f(){System.out.println("noname class invoke f method!");}
};
}
}