引用
这里没有讲解理论是怎么样的,我用实例说明,个人觉得比理论更来得实际,并写下了测试的总结。
如需要补充理论的请参看这篇文章:关于JAVA匿名内部类,回调,事件模式的一点讨论
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class InnerTest {
- static int a;
- InnerTest()
- {
- new T1();
- new T2();
- }
-
-
-
- private class T1{
- T2 t2=new T2();
- T1()
- {
- a++;
-
- System.out.println(addLong(1,2));
- System.out.println(add(1,2));
- }
- }
-
-
-
- static class T2{
-
-
- T2()
- {
- System.out.println(add(1,2));
-
-
- }
- }
-
- long addLong(long a,long b)
- {
- return a+b;
- }
- public static int add(int a,int b)
- {
- return a+b;
- }
- void callT2()
- {
- new T2();
- }
- public static void main(String[] args) {
-
- InnerTest it=new InnerTest();
- it.callT2();
-
- T1 t1=new InnerTest().new T1();
-
- T2 t2=new T2();
- }
-
- }