package com.shiro.Utils;
public class test {
public static void main(String[] args) {
pricth();
test1();
}
public static void pricth() {
doRequest(new inInterface1() {
@Override
public void onResponse(int resultCode, String resultJson) {
System.out.println(resultCode + " " + resultJson);
}
});
}
private static void doRequest(final inInterface1 callback) {
callback.onResponse(1, "ok");
}
static void test1() {
interface2 ss = new interface2() {
@Override
public void testMethod1() {
System.out.println("interface2:testMethod1");
}
};
ss.testMethod1();
}
interface inInterface1 {
void onResponse(int resultCode, String resultJson);
public static class Bulder {
public Bulder() {
System.out.println("inInterface.Bulder");
}
}
}
interface interface2 {
void testMethod1();
}
}
上面的代码很妙!
1.接口里面可以定义静态类,用于创建接口实现,javaApi源码里面有很多这样的设计
2.内部类回调方式