Java 泛型:添加'List<;字符串>;`至`列表<;对象>`

Java 泛型:添加'List<;字符串>;`至`列表<;对象>`,java,generics,collections,Java,Generics,Collections,我不擅长泛型,但有人能告诉我如何才能在下面的代码中将List添加到List? 或者,我遗漏了一些非常基本的东西 该方法不适用,因为字符串是对象但是 列表不是列表 您试图将实际的列表添加到列表中,该列表可能只包含字符串s,要成功添加每个单独的项目,您需要循环通过testObj列表并单独添加它们 for (Object obj : testObj) { testString.add(String.valueOf(obj)); } [TestObjValue1, TestObjValue2

我不擅长泛型,但有人能告诉我如何才能在下面的代码中将
List
添加到
List
? 或者,我遗漏了一些非常基本的东西

该方法不适用,因为
字符串
对象
但是
列表
不是
列表


您试图将实际的
列表
添加到
列表
中,该列表可能只包含
字符串
s,要成功添加每个单独的项目,您需要循环通过
testObj
列表并单独添加它们

for (Object obj : testObj) {
    testString.add(String.valueOf(obj));
}
[TestObjValue1, TestObjValue2, TestObjValue3, TestObjValue4, 
[TestStrValue1, TestStrValue2, TestStrValue3, TestStrValue4]]


[TestObjValue1, TestObjValue2, TestObjValue3, TestObjValue4,
[TestStrValue1, TestStrValue2, TestStrValue3, TestStrValue4],
TestStrValue1, TestStrValue2, TestStrValue3, TestStrValue4]
for (Object obj : testObj) {
    testString.add(String.valueOf(obj));
}