有人能给我解释一下以下代码吗?这段代码来自Android源代码。
第一行看起来是初始化一个整数数组,但是花括号中的代码怎么样呢?我的意思是,这些代码的语法是否正确,因为花括号部分似乎有点混乱?
第一行看起来是初始化一个整数数组,但是花括号中的代码怎么样呢?我的意思是,这些代码的语法是否正确,因为花括号部分似乎有点混乱?
// high priority first
mPriorityList = new int[mNetworksDefined];
{
int insertionPoint = mNetworksDefined-1;
int currentLowest = 0;
int nextLowest = 0;
while (insertionPoint > -1) {
for (NetworkAttributes na : mNetAttributes) {
if (na == null) continue;
if (na.mPriority < currentLowest) continue;
if (na.mPriority > currentLowest) {
if (na.mPriority < nextLowest || nextLowest == 0) {
nextLowest = na.mPriority;
}
continue;
}
mPriorityList[insertionPoint--] = na.mType;
}
currentLowest = nextLowest;
nextLowest = 0;
}
}
}
关闭后,变量insertionPoint
、currentLowest
和nextLowest
不再使用。带有new[]
的块可以放置在单独的初始化方法中。 - Joop Eggen