首先,我尝试了:

public class WeightedEdge280<V> extends Edge280<V>{


这给了我错误:

"Bound mismatch: The type V is not a valid substitute for the bounded parameter <V extends Vertex280> of the type Edge280<V>"


所以我尝试了:

public class WeightedEdge280<V> extends Edge280<V extends Vertex280>{...


这给了我错误:

"Syntax error on token "extends", , expected"


边缘类:

public class Edge280<V extends Vertex280> extends Pair280<V, V> {...


作业说明:

The first step is to create the class for the custom edge object, let’s call it WeightedEdge280<V>. It should be an extension of Edge280<V>

最佳答案

扩展泛型类时,需要引入相同的界限:

public class WeightedEdge280<V extends Vertex280> extends Edge280<V>


原因是您已声明Edge extends Vertex280中的泛型类型参数。创建扩展Edge的类时,需要确保其通用类型参数也至少紧密地绑定在一起。这是因为WeightedEdge280的通用类型必须始终是Edge280的有效通用类型。

否则我可以做类似的事情:

final WeightedEdge280<String>

07-24 18:37
查看更多