在初始化阶段,类中包含的静态初始化器都被执行。
During the initializing phase, any static initializers contained within a class are executed.
带有静态初始化器的permissions类为声明和配置可用的应用程序权限提供单一位置。
A permissions class with a static initializer provides a single location for declaring and configuring available application permissions.
我们将在类的静态初始化器中把 EmbeddedDriver 用于驱动程序类。
We use the EmbeddedDriver for our driver class in the static initializer of the class.
Permissions从不实例化,它提供构建Enum类型的静态初始化器,该Enum类型可以为应用程序配置权限。
Permissions is never instantiated — it features a static initializer that builds up the enum types that configure permissions for the application.
提供描述构造函数的gbeaninfo静态初始化器。
Provide a GBeanInfo static initializer that describes the constructor.
第二种情况是,类型具有一个用于静态字段的初始值设定项,在这种情况下,编译器会在后台添加类型构造函数。
The second scenario is when a type has a initializer for a static field, in which case the compiler adds a type constructor behind the scenes.
清单2显示了典型的静态初始化器。
清单2中的静态初始化器显示了Customer类的注册过程,这个类包含两个属性:name和salary。
The static initializer in Listing 2 shows the registration process for a Customer class that contains two properties: name and salary.
这条信息位于beaninfo类中,该类通常在bean的类通过静态初始化器装入时,由bean提供。
This information resides in a BeanInfo class, which is typically provided by your bean when the bean's class is loaded via a static initializer.
加载类之后,静态初始化器首先运行,紧接着运行的是main方法(也是静态的)。
The static initializer runs first, as the class is loaded, followed by the main method (which is also static).
和实例初始化一样,可以使用初始化器语法作为静态构造函数的变体。
As with instance initialization, you can use the initializer syntax as an alternative to the static constructor.
如果你需要简单的分配一个静态成员,那么可以使用初始化器语法。
If you simply need to allocate a static member, use the initializer syntax.
如果使用静态初始化器,就不可能自己捕获异常了。
If you use static initializers, you cannot catch the exceptions yourself.
静态初始化器和静态构造函数提供了最洁净的、最间接的方式来初始化类的静态成员。
Static initializers and static constructors provide the cleanest, clearest way to initialize static members of your class.
使用静态构造器初始化静态类成员。
使用静态构造器初始化静态类成员。
应用推荐