这是来自 Android Developer's Website
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
try {
ndef.addDataType("*/*"); /* Handles all MIME based dispatches.
You should specify only the ones that you need. */
}
catch (MalformedMimeTypeException e) {
throw new RuntimeException("fail", e);
}
intentFiltersArray = new IntentFilter[] {ndef, };
所以在这里,intentFiltersArray[0] = ndef
。 intentFiltersArray[1]
及以后呢?在上面的代码中,ndef
之后有一个,
是什么意思?
同样,它还有另一个代码示例
techListsArray = new String[][] { new String[] { NfcF.class.getName() } };
这里techListsArray[][]
是怎么初始化的?我猜 techListsArray[0][0]=NfcF.class.getName()
(应该是 NfcF
不应该吗?)但是其他元素呢?还是只有一个元素?
最佳答案
So here,
intentFiltersArray[0] = ndef
. What aboutintentFiltersArray[1]
and beyond?
[1]
或“beyond”处没有元素。
您正在创建一个只有一个元素的数组。如果您尝试访问 intentFiltersArray[1]
,您将得到一个未经检查的异常:ArrayIndexOutOfBoundsException
.
What does having a comma after
ndef
mean in the above code?
没有任何意义。 Java 语言语法允许在数组初始值设定项列表的末尾使用冗余逗号。 (从表面上看,是为了让源码生成更简单……)
现在你的第二个例子:
How is techListsArray[][] initialized here?
它被初始化为一个 1x1 的字符串数组:
techListsArray[0]
是一个只有一个元素的String[]
。techListsArray[0][0]
是一个字符串 ...NfcF
类的完全限定名称;例如“some.pkg.NfcF”
。
关于java - 这里进行了什么样的数组初始化(Basic Java)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18051154/