gpt4 book ai didi

Java 与 Eclipse : Type Safety: The Expression of type map needs unchecked conversion to confirm to Map

转载 作者:行者123 更新时间:2023-12-01 16:37:07 30 4
gpt4 key购买 nike

如何使用 Eclipse 删除 Java 中“Map”后面的类型安全标记?

Map<String, String> errorStatus = exchange.getIn().getHeader("totalCount", Map.class);

它打印以下消息。

The Expression of type map needs unchecked conversion to confirm to Map<String,String>

enter image description here

更新:

getIn() 和 getHeader 是内置的 Camel 方法。在一条 route ,我有 setHeader("headerkey",mapOfErrors) ,当我进一步需要这个错误键时,我只是使用这些函数从 Camel Message 中获取它。以下是 getHeader() 的可用参数: enter image description here

最佳答案

如您所知,没有 Map<String,String>.class ,据我所知,对于您的情况,您有两种选择:首先创建一个包装类来扩展 HashMap,然后您可以使用 Wapper.class,我不推荐

WrapperClass errorStatus = exchange.getIn().getHeader("totalCount", Wrapper.class);

第二种方法只是忽略此警告并使用 @SuppressWarnings("unchecked")

关于Java 与 Eclipse : Type Safety: The Expression of type map needs unchecked conversion to confirm to Map<String, 字符串>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61931925/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com