【发布时间】:2013-07-25 15:25:47
【问题描述】:
我正在研究这段代码,但我不明白这一行的作用:[(y << 3) + x]
for (int y = 0; y <= 7; ++y) {
for (int x = 0; x <= 7; ++x) {
final String pieceCode = pieceCodes[(y << 3) + x];
if (pieceCode.length() != 2) throw new IllegalArgumentException();
if (!pieceCode.equals("--")) {
pieces[((7 - y) << 3) + x] = CheckersPiece.valueOf(pieceCode.charAt(0), pieceCode.charAt(1));
}
}
}
【问题讨论】:
-
看起来它正在索引存储在单个数组中的二维数组。
-
@DaveNewton 我想就是这样!
标签: java