I’ve never seen this before – what is it called? This is a class level variable, at the beginning of the file.
Just to be clear, I’m referring to the static {} after the variable.
private static final UriMatcher URI_MATCHER;
static {
URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
URI_MATCHER.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH);
URI_MATCHER.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH);
URI_MATCHER.addURI(AUTHORITY, "books", BOOKS);
URI_MATCHER.addURI(AUTHORITY, "books/#", BOOK_ID);
}
It’s an static initialization block. It can be declared anywhere inside a class (but outside a method), but by convention it’s usually written right after the static variable that’s being initialized. It’s specified in the Java Language Specification, section §8.7.
As the name implies, it’s normally used for initializing the state of static attributes in the class at class-loading time. From the Java tutorial: