我真的不明白以下static
阻止。我在使用方法和变量时理解static关键字,但我不确切知道下面代码中静态关键字的用途是什么。
static
{
sURIMatcher.addURI("contacts", "people", PEOPLE);
sURIMatcher.addURI("contacts", "people/#", PEOPLE_ID);
sURIMatcher.addURI("contacts", "people/#/phones", PEOPLE_PHONES);
sURIMatcher.addURI("contacts", "people/#/phones/#", PEOPLE_PHONES_ID);
sURIMatcher.addURI("contacts", "people/#/contact_methods", PEOPLE_CONTACTMETHODS);
sURIMatcher.addURI("contacts", "people/#/contact_methods/#", PEOPLE_CONTACTMETHODS_ID);
sURIMatcher.addURI("contacts", "deleted_people", DELETED_PEOPLE);
sURIMatcher.addURI("contacts", "phones", PHONES);
sURIMatcher.addURI("contacts", "phones/filter/*", PHONES_FILTER);
sURIMatcher.addURI("contacts", "phones/#", PHONES_ID);
sURIMatcher.addURI("contacts", "contact_methods", CONTACTMETHODS);
sURIMatcher.addURI("contacts", "contact_methods/#", CONTACTMETHODS_ID);
sURIMatcher.addURI("call_log", "calls", CALLS);
sURIMatcher.addURI("call_log", "calls/filter/*", CALLS_FILTER);
sURIMatcher.addURI("call_log", "calls/#", CALLS_ID);
}
答案 0 :(得分:7)
这在Java中称为静态初始化程序块。这将在类加载时执行。红色这个oracle tutorial。
静态初始值设定项可用于初始化类的类变量。
答案 1 :(得分:5)
来自Java Language Specification:
在类中声明的类中声明的静态初始化程序 初始化(§12.4.2)。与课程的任何字段初始化程序一起使用 变量(§8.3.2),静态初始化器可用于初始化 类的类变量。
StaticInitializer:
static Block