Java - Type对象的LinkedLists的LinkedList

时间:2015-10-25 20:01:48

标签: java object linked-list

我声明flink-runtime-1.0-SNAPSHOT flink-streaming-java-1.0-SNAPSHOT flink-connector-kafka-1.0-SNAPSHOT flink-java8-1.0-SNAPSHOT flink-core-1.0-SNAPSHOT flink-java-1.0-SNAPSHOT org.apache.hadoop:hadoop-core:1.2.1 flink-clients-1.0-SNAPSHOT org.apache.kafka:kafka-clients:0.8.2.2 org.apache.kafka:kafka_2.11:0.8.2.2 flink-optimizer-1.0-SNAPSHOT org.apache.sling:org.apache.sling.commons.json:2.0.6 de.javakaffee:kryo-serializers:0.28 com.github.scopt:scopt_2.11:3.3.0 org.clapper:grizzled-slf4j_2.9.0:0.6.6 com.typesafe.akka:akka-osgi_2.11:2.4.0 com.typesafe.akka:akka-slf4j_2.11:2.4.0 LinkedList LinkedListGraphEdge如下:

首先声明LinkedList和固定长度(对于全局numVertices):

LinkedList[] adjList = new LinkedList[numVertices];

然后将每个adjList[i]初始化为新的LinkedList<GraphEdge>()

for (i = 0; i < this.numVertices; i++) {
    adjList[i] = new LinkedList<GraphEdge>();
}

但是我在尝试打电话时遇到错误:

GraphEdge nextEdge = adjList[v].peekFirst();

1 个答案:

答案 0 :(得分:1)

使用LinkedList<LinkedList<GraphEdge>>代替数组来保留泛型类型信息或添加强制转换。

GraphEdge nextEdge = (GraphEdge)adjList[v].peekFirst();

演员是一个丑陋,糟糕的解决方案。