如果这个匿名类可被作为一个内部类单独放置,那么清单1中的代码将会简洁很多。
The code in Listing 1 would be much neater if the anonymous class was placed separately as an inner class.
相比于每个匿名内部类都要对应一个类的做法来说,这种方式是个极大的改进,同时也使得代码的可读性更好。
This is an improvement over having to write a class any time an anonymous inner class is needed and can help keep the code more self-documenting.
我以前可能提到过,您将经常看到定义为匿名内部类的asynccallback类。
As I probably mentioned before, you'll frequently see AsyncCallback classes defined as anonymous inner classes.
惟一需要以这种方式使用一个类的是一个默认构造函数(它允许您创建继承自类的一个匿名内部类)。
The only thing a class needs to be used this way is a default constructor (which allows you to create an anonymous inner class instance inheriting from your class).
addOrderFrom()方法成为公共类的匿名内部类创建的定义,将这两个工作项目包装起来。
The addOrderFrom() method collapses to the definition of an anonymous inner class creation of the command class, wrapping the two work items.
事实上,一个匿名内部类甚至不能同时扩展一个类和实现一个借口。
In fact, an anonymous inner class can't even extend a class and implement an interface at the same time.
事实上,一个匿名内部类甚至不能同时扩展一个类和实现一个借口。
In fact, an anonymous inner class can't even extend a class and implement an interface at the same time.
应用推荐