Anonymous inner class overview

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qunqunstyle99/article/details/100133952
  1. Anonymous inner classes can not define any static members, method ( 内部类不能一开始就实例化,需要实例化外部类才能实例化它,外部类不是默认加载的,他只有在手动实例化之后才有内存分配,产生矛盾).
  2. Method anonymous inner classes can not be abstract ( 因为在创建匿名内部类的时候,会立即创建匿名内部类的对象。从而也可知匿名内部类必须实现它的抽象父类或者接口里包含的所有抽象方法);
  3. Anonymous inner classes can not be public, protected, private, static.
  4. Because when you create an anonymous inner class, create an instance of it immediately, you can see anonymous inner class can not be abstract classes, interfaces, or all of the abstract methods abstract parent class must implement.
  5. Anonymous inner classes is not defined Constructor ( 因为没有类名);
  6. Anonymous inner classes 访问的外部类成员变量或成员方法必须用static修饰;
  7. Internal class can access external private class variables and methods, by 外部类名.方法名direct access.
  8. 因为生命周期的问题The external parameters are passed into the use of anonymous inner class must be defined as final, otherwise it will error.

Guess you like

Origin blog.csdn.net/qunqunstyle99/article/details/100133952