【发布时间】:2013-10-26 09:10:47
【问题描述】:
我有一个类,GraphSearch,定义如下:
public class GraphSearch{
///code
}
在这个类中是泛型参数化方法:
public static <T> int dsp(T start, Map<T, List<Pair<T, Integer>>> adjList, T goal) {
///code}
我有一个主要的我做这个设置并调用方法:
GraphSearch g = new GraphSearch();
HashMap<String,ArrayList<Pair<String,Integer>>> k = new HashMap<String, ArrayList<Pair<String, Integer>>>();
////various setup to fill my map with valid stuff
///Pair is a class I made in my package
那么主要是
System.out.println("dsp from A to E is" + g.dsp("a", k, "e"));
我收到一个错误。
The method dsp(T, Map<T,List<Pair<T,Integer>>>, T) in the type GraphSearch is not applicable for the arguments (String, HashMap<String,ArrayList<Pair<String,Integer>>>, String)
好吧,为什么不呢? ArrayList 不是列表吗?字符串不是通用可接受的类型吗? Hashmap 不是 Map 吗?
发生了什么事?
【问题讨论】: