为什么我不能创建List数组?
List<String>[] nav = new List<String>[] { new ArrayList<String>() };
Run Code Online (Sandbox Code Playgroud)
Eclipse说"无法创建List的通用数组"
要么
ArrayList<String>[] nav = new ArrayList<String>[] { new ArrayList<String>() };
Run Code Online (Sandbox Code Playgroud)
Eclipse说"无法创建ArrayList的通用数组"
要么
List<String>[] getListsOfStrings() {
List<String> groupA = new ArrayList<String>();
List<String> groupB = new ArrayList<String>();
return new List<String>[] { groupA, groupB };
}
Run Code Online (Sandbox Code Playgroud)
但我可以这样做:
List[] getLists() {
return new List[] { new ArrayList(), new ArrayList() };
}
Run Code Online (Sandbox Code Playgroud)
Eclipse说List和ArrayList是原始类型,但它编译...
看起来很简单,为什么它不起作用?
通过简化的XSD获取以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="com.acme" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Widget">
<xs:complexType>
<xs:sequence>
<xs:element
minOccurs="0" name="color" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="WidgetColor" type="xs:string" />
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
然后,尝试以下操作:
xjc test.xsd
Run Code Online (Sandbox Code Playgroud)
您应该总是得到以下异常:
parsing a schema...
compiling a schema...
[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 11 of file:/C:/test.xsd
[ERROR] (Related to above error) This is the other declaration.
line 7 of file:/C:/test.xsd
Failed to produce code.
Run Code Online (Sandbox Code Playgroud)
请注意,元素名称" Widget "是complexType,并且具有名为" color "的元素.在元素" Widget " 的同一级别,还有一个名为" WidgetColor " 的简单元素.
什么是更令人费解的是,如果你删除 …