java - 了解static {}

时间:2014-01-07 13:13:54

标签: java android java-ee

我遇到了这段代码,其中我不明白static {}的含义:

public class BookProvider extends ContentProvider
{

private static final String TAG = "BookProvider";

private static HashMap<String, String> sBooksProjectionMap;
static
{
sBooksProjectionMap = new HashMap<String, String>();
sBooksProjectionMap.put(BookTableMetaData._ID,
BookTableMetaData._ID);

sBooksProjectionMap.put(BookTableMetaData.BOOK_NAME,

}

1 个答案:

答案 0 :(得分:1)

这是一个静态初始化程序。它是在加载(或初始化)类时执行的。

有关详情,请参阅http://docs.oracle.com/javase/tutorial/java/javaOO/initial.html