2014-03-19 33 views
1

首先我想:泛型: 「令牌語法錯誤 」擴展「,預計」

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> 

回答

1

你需要,當你擴展一個泛型類引入相同的邊界:

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

的原因是,您已聲明Edgeextends Vertex280中的泛型類型參數。當您創建一個擴展爲Edge的類時,您需要確保其泛型類型參數的界限至少相同。這是因爲WeightedEdge280的泛型類型必須始終爲Edge280的有效泛型類型。

否則我可以這樣做:

final WeightedEdge280<String> 
2

我想你的意思是:通用參數定義,其中

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

的範圍應符合規定。

相關問題