java.lang和java.util_java.lang.String不能转换为java.util.Map

我想你需要清理你的泛型入手:

Set> section = array.entrySet();

Iterator> sectionI = section.iterator();

while (sectionI.hasNext()) {

Map.Entry sectionInfo = sectionI.next();

Map subMap = (Map) sectionInfo.getValue(); // is this actually a Map?

Set> subSet = subMap.entrySet();

Iterator> subI = subSet.iterator();

while (subI.hasNext()) {

Map.Entry subInfo = subI.next();

Map subsubMap = (Map) subInfo.getValue(); // is this actually a Map?

Set> subsubSet = subsubMap.entrySet();

Iterator> subsubI = subsubSet.iterator();

while (subsubI.hasNext()) {

System.out.println("test");

Map.Entry subsubInfo = subsubI.next();

Map subcontentsMap = (Map) subsubInfo.getValue(); // somehow a String got in here?

/*

The above line seems to be causing the issues.

If you comment out the rest of this loop (below this comment)

the error will still appear. If you comment out the rest of this loop

(including the line above this comment) it disappears.

Power of deduction my dear Watson.

*/

Set> subcontentsSet = subcontentsMap.entrySet();

Iterator> keys = subcontentsSet.iterator();

while (keys.hasNext()) {

Map.Entry keyMap = keys.next();

}

Iterator> values = subcontentsSet.iterator();

while (values.hasNext()) {

Map.Entry valueMap = values.next();

}

}

}

}

然后,你应该更明确的与你的array声明:

public static Map>>> array = new HashMap>>>();

这将确保你是丘比特将正确的对象分配到每个地图中。您将永远无法获得put a String值,因为它不会被编译,因此需要Map<>。这将允许你写下面的代码(而无需强制转换):

final Set>>>> section = array.entrySet();

final Iterator>>>> sectionI = section.iterator();

while (sectionI.hasNext()) {

final Entry>>> sectionInfo = sectionI.next();

final Map>> subMap = sectionInfo.getValue();

final Set>>> subSet = subMap.entrySet();

final Iterator>>> subI = subSet.iterator();

while (subI.hasNext()) {

final Map.Entry>> subInfo = subI.next();

final Map> subsubMap = subInfo.getValue();

final Set>> subsubSet = subsubMap.entrySet();

final Iterator>> subsubI = subsubSet.iterator();

while (subsubI.hasNext()) {

System.out.println("test");

final Map.Entry> subsubInfo = subsubI.next();

final Map subcontentsMap = subsubInfo.getValue();

final Set> subcontentsSet = subcontentsMap.entrySet();

final Iterator> entries = subcontentsSet.iterator();

while (entries.hasNext()) {

final Map.Entry entry = entries.next();

}

}

}

}

之所以这么说,所有这些嵌套泛型的很难看。我建议你创建一些对象来表示你的数据。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值