定制边供应商错误:如何编写通用方法?

时间:2019-02-28 16:08:13

标签: generics jgrapht

试图使我的项目独立于Edge和Nodetype,我正在使用尽可能多的泛型,但是,在实例化一个新的Graph以提供Edgetype时,我遵循以下规则:How to get a class instance of generics type T

问题我得到一个错误:

  

线程“主”中的异常java.lang.RuntimeException:供应商失败     在   org.jgrapht.util.SupplierUtil.lambda $ createSupplier $ 32fc57c8 $ 1(SupplierUtil.java:64)     在   org.jgrapht.graph.Abs​​tractBaseGraph.addEdge(AbstractBaseGraph.java:246)     在Perspective.StructureMap.investigateGraph(StructureMap.java:54)

StructureData<V, E> struc=new StructureData<V, E>(cls);
struc.g.addEdge(knot,nachb);

public class StructureData<V, E> {

private Class<E> cls;
public StructureData(Class<E> cls)
{
    this.cls=cls;
}
//public SimpleDirectedGraph<Object,Edge> g= new SimpleDirectedGraph<Object,Edge>(Edge.class);
public SimpleDirectedGraph<Object,E> g= new SimpleDirectedGraph<Object,E>(cls);
public Map<V,V> excluded= new HashMap<V,V>();
public Set<PlaceholderNode> substitutes=new HashSet<PlaceholderNode>();
public HashMap<Object,Integer> generation=new HashMap<Object,Integer>();
public HashMap<Object,Integer> branch=new HashMap<Object,Integer>();
public HashMap<Object,Object> previous=new HashMap<Object,Object>();
}

0 个答案:

没有答案