我有两个由 (i) s 和 (ii) Multimap
sString
索引的s 和一个输出 s 列表的例程。Integer
Double
String
public static void outputInteger(Multimap<Integer, String> map) {
for (Integer key : map.keySet()) {
Collection<String> strings = map.get(key);
output(strings);
}
}
public static void outputDouble(Multimap<Double, String> map) {
for (Double key : map.keySet()) {
Collection<String> strings = map.get(key);
output(strings);
}
}
我想将这些组合成一个例程,Number
用作和的超Integer
类Double
public static void outputNumber(Multimap<? extends Number, String> map) {
for (Number key : map.keySet()) {
Collection<String> ids = map.get(key); //**
}
}
但带星号的行无法编译
The method get(capture#5-of ? extends Number) in the type
Multimap<capture#5-of ? extends Number,String> is not
applicable for the arguments (Number)
我该如何解决这个问题?