I saw these codes.
I've never seen such constructor, but I guess that it creates a new A instance with the implementation of a abstract method.
what is it called?
new A() {
@Override
public void onEvent() {
dosomething();
}
};
are you referring to an anonymous class ? Its when you provide an implementation but never define a named class. In other words, you are providing an object in-place; you cannot reuse that definition elsewhere because you never wrote class MyClass {}
, which is why it's "anonymous".
这是一个类型A的Object,它覆盖了A类的onEvent方法。这称为匿名类,它覆盖了一个方法
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.