Anonymous inner class are local inner classes that don't have a class name.
匿名内部类是局部的内部类,它没有名字。
Instance initializers allow you to execute construction code for an anonymous inner class.
实例初始化器允许您为一个匿名内部类执行构造代码。
In fact, an anonymous inner class can't even extend a class and implement an interface at the same time.
事实上,一个匿名内部类甚至不能同时扩展一个类和实现一个借口。
For example, only final object references from the outer class are invokable within the body of the anonymous inner class.
例如,在匿名内联类的主体中,只能调用外部类中的final对象引用。
Here, the ActionListener implementation is defined in place, as an anonymous inner class, and directly attached to the button.
这里,ActionListener实现是适时定义的,它定义为一个匿名内部类,并直接附加到按钮上。
This restriction is lifted in Groovy; you can change the values of variables in a containing scope from within an anonymous inner class.
Groovy则消除了这种限制,在Groovy中,匿名内部类可以修改外部的变量值。
The addOrderFrom() method collapses to the definition of an anonymous inner class creation of the command class, wrapping the two work items.
addOrderFrom()方法成为公共类的匿名内部类创建的定义,将这两个工作项目包装起来。
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.
相比于每个匿名内部类都要对应一个类的做法来说,这种方式是个极大的改进,同时也使得代码的可读性更好。
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).
惟一需要以这种方式使用一个类的是一个默认构造函数(它允许您创建继承自类的一个匿名内部类)。
The first set of enclosing braces delineates the construction of an anonymous inner class, and the second set delineates the instance initializer for the anonymous inner class.
第一组闭合括弧划定一个匿名内部类的构造,第二组划定匿名内部类的实例初始化语句块。
I'm left with some ugly boilerplate code because of the anonymous inner class wrapping this method's real purpose - the two lines of code that appear in the body of the addOrderFrom method.
考虑到包装这个方法的匿名内部类的真正用途,我留下了几行难看的样板代码—addorderfrom方法体中的两行代码。
The code in Listing 1 would be much neater if the anonymous class was placed separately as an inner class.
如果这个匿名类可被作为一个内部类单独放置,那么清单1中的代码将会简洁很多。
Two things are worth mentioning when considering this code: First, the instantiation of an anonymous inner callback class requires a great amount of boilerplate code.
上面的代码有两点值得我们注意:首先,匿名内部回调类的实例化需要大量的样板代码。
Two things are worth mentioning when considering this code: First, the instantiation of an anonymous inner callback class requires a great amount of boilerplate code.
上面的代码有两点值得我们注意:首先,匿名内部回调类的实例化需要大量的样板代码。
应用推荐