必需Set <string>,但'of'被推断为ImmutableSet <e>

时间:2018-01-19 00:41:25

标签: guava

我正在尝试在构造函数中传入Set<String>,但是我收到以下错误:

Incompatible types. Required Set<String> but 'of' was inferred to ImmutableSet<E>: no instance(s) of type variable(s) E exist so that ImmutableSet<E> conforms to Set<String>

以下是代码:

final CustomMetricsModule customMetricsModule = new CustomMetricsModule(Collections.EMPTY_MAP,
                ImmutableSet.of("val", "val1"));

CustomMetricsModule有一张地图,Set<String>为其参数。

1 个答案:

答案 0 :(得分:0)

通过更改导入的Set修复了问题。在CustomMetricsModule中,我应该导入java.util.Set,但我不是。